ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2024-10-11 09:26:44
Exec Total Coverage
Lines: 1944 4483 43.4%
Functions: 136 332 41.0%
Branches: 1310 3736 35.1%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro5/joystick.h"
6 #include "base/files.h"
7 #include "base/render.h"
8 #include "zalleg/zalleg.h"
9 #include "base/qrs.h"
10 #include "base/dmap.h"
11 #include <functional>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <cstring>
15 #include <math.h>
16 #include <map>
17 #include <filesystem>
18 #include <ctype.h>
19 #include <sstream>
20 #include "base/version.h"
21 #include "base/zc_alleg.h"
22 #include "gamedata.h"
23 #include "zc/replay_upload.h"
24 #include "zc/zc_init.h"
25 #include "init.h"
26 #include "zc/replay.h"
27 #include "zc/cheats.h"
28 #include "zc/render.h"
29 #include "base/zc_math.h"
30 #include "base/zapp.h"
31 #include "dialog/cheatkeys.h"
32 #include "metadata/metadata.h"
33 #include "zc/zelda.h"
34 #include "zc/saves.h"
35 #include "tiles.h"
36 #include "base/colors.h"
37 #include "pal.h"
38 #include "base/zsys.h"
39 #include "base/qst.h"
40 #include "zc/zc_sys.h"
41 #include "play_midi.h"
42 #include "gui/jwin_a5.h"
43 #include "base/jwinfsel.h"
44 #include "base/gui.h"
45 #include "midi.h"
46 #include "subscr.h"
47 #include "zc/maps.h"
48 #include "sprite.h"
49 #include "zc/guys.h"
50 #include "zc/hero.h"
51 #include "zc/title.h"
52 #include "particles.h"
53 #include "sound/zcmusic.h"
54 #include "zconsole.h"
55 #include "zc/ffscript.h"
56 #include "dialog/info.h"
57 #include "dialog/alert.h"
58 #include "zc/combos.h"
59 #include "zc/jit.h"
60 #include "zc/zc_subscr.h"
61 #include <fmt/format.h>
62 #include "zconsole/ConsoleLogger.h"
63 #include "zinfo.h"
64 #include "base/misctypes.h"
65 #include "music_playback.h"
66 #include <base/new_menu.h>
67 #include <base/files.h>
68
69 #ifdef __EMSCRIPTEN__
70 #include "base/emscripten_utils.h"
71 #endif
72
73 using namespace std::chrono_literals;
74
75 extern bool Playing;
76 int32_t sfx_voice[WAV_COUNT];
77 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
78 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
79
80 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
81 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
82
83 extern byte monochrome_console;
84
85 extern HeroClass Hero;
86 extern zcmodule moduledata;
87 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
88 extern particle_list particles;
89 extern int32_t loadlast;
90 extern char *sfx_string[WAV_COUNT];
91 byte use_dwm_flush;
92 byte use_save_indicator;
93 int32_t paused_midi_pos = 0;
94 byte midi_suspended = 0;
95 byte zc_192b163_warp_compatibility;
96 char modulepath[2048];
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 static const char *qst_module_name = "current_module";
111 #ifdef ALLEGRO_LINUX
112 static const char *samplepath = "samplesoundset/patches.dat";
113 #endif
114 char qst_files_path[2048];
115
116 extern TopMenu the_player_menu;
117 #ifdef _MSC_VER
118 #define getcwd _getcwd
119 #endif
120
121 bool rF11();
122 bool rI();
123 bool rQ();
124 bool zc_key_pressed();
125
126 #ifdef _WIN32
127
128 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
129 extern "C"
130 {
131 typedef HRESULT(WINAPI *t_DwmFlush)();
132 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
133 }
134
135 void do_DwmFlush()
136 {
137 static HMODULE shell = LoadLibrary("dwmapi.dll");
138
139 if(!shell)
140 return;
141
142 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
143 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
144
145 BOOL enabled;
146 isEnabled(&enabled);
147
148 if(isEnabled)
149 flush();
150 }
151
152 #endif // _WIN32
153
154 259 void zc_exit(int code)
155 {
156 extern CConsoleLoggerEx zscript_coloured_console;
157
158
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if (replay_get_mode() == ReplayMode::Record) replay_save();
159 259 replay_stop();
160 259 music_stop();
161 259 kill_sfx();
162
163
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 253 times.
259 if (get_qr(qr_OLD_SCRIPT_VOLUME))
164 {
165 //restore user volume settings
166
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 1 times.
253 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
167 {
168 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
169 1 }
170
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 1 times.
253 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
171 {
172 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
173 1 }
174
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 1 times.
253 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
175 {
176 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
177 1 }
178
1/2
✓ Branch 0 taken 253 times.
✗ Branch 1 not taken.
253 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
179 {
180 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
181 }
182 253 }
183
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
184 {
185 pan_style = (int32_t)FFCore.usr_panstyle;
186 }
187 259 save_game_configs();
188
189 259 zscript_coloured_console.kill();
190 259 jit_shutdown();
191 259 quit_game();
192
193 259 Z_message("ZQuest Classic web site: https://zquestclassic.com\n");
194 259 Z_message("ZQuest Classic old wiki: https://web.archive.org/web/20210910193102/https://zeldaclassic.com/wiki\n");
195 259 Z_message("ZQuest Classic new wiki: https://github.com/ZQuestClassic/ZQuestClassic/wiki\n");
196
197 259 allegro_exit();
198 259 exit(code);
199 }
200
201 92829 bool flash_reduction_enabled(bool check_qr)
202 {
203
4/4
✓ Branch 0 taken 88404 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87576 times.
✓ Branch 3 taken 92001 times.
92829 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
204 }
205
206 // Dialogue largening
207 void large_dialog(DIALOG *d)
208 {
209 large_dialog(d, 1.5);
210 }
211
212 void large_dialog(DIALOG *d, float RESIZE_AMT)
213 {
214 if(!d[0].d1)
215 {
216 d[0].d1 = 1;
217 int32_t oldwidth = d[0].w;
218 int32_t oldheight = d[0].h;
219 int32_t oldx = d[0].x;
220 int32_t oldy = d[0].y;
221 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
222 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
223 d[0].w = int32_t(d[0].w*RESIZE_AMT);
224 d[0].h = int32_t(d[0].h*RESIZE_AMT);
225
226 for(int32_t i=1; d[i].proc !=NULL; i++)
227 {
228 // Place elements horizontally
229 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
230 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
231
232 if(d[i].proc != d_stringloader)
233 {
234 if(d[i].proc==d_bitmap_proc)
235 {
236 d[i].w *= 2;
237 }
238 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
239 }
240
241 // Place elements vertically
242 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
243 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
244
245 // Vertically resize elements
246 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
247 {
248 d[i].h = int32_t((double)d[i].h*1.5);
249 }
250 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
251 {
252 d[i].y += int32_t((double)d[i].h*0.25);
253 d[i].h = int32_t((double)d[i].h*1.25);
254 }
255 else if(d[i].proc==d_bitmap_proc)
256 {
257 d[i].h *= 2;
258 }
259 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
260
261 // Fix frames
262 if(d[i].proc == jwin_frame_proc)
263 {
264 d[i].x++;
265 d[i].y++;
266 d[i].w-=4;
267 d[i].h-=4;
268 }
269 }
270 }
271
272 for(int32_t i=1; d[i].proc!=NULL; i++)
273 {
274 if(d[i].proc==jwin_slider_proc)
275 continue;
276
277 // Bigger font
278 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
279
280 if(!d[i].dp2 && bigfontproc)
281 {
282 d[i].dp2 = get_zc_font(font_lfont_l);
283 }
284 else if(!bigfontproc)
285 {
286 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
287 }
288
289 // Make checkboxes work
290 if(d[i].proc == jwin_check_proc)
291 d[i].proc = jwin_checkfont_proc;
292 else if(d[i].proc == jwin_radio_proc)
293 d[i].proc = jwin_radiofont_proc;
294 }
295
296 jwin_center_dialog(d);
297 }
298
299 static char cfg_sect[] = "zeldadx"; //We need to rename this.
300 static char ctrl_sect[] = "Controls";
301 static char sfx_sect[] = "Volume";
302
303 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
304 {
305 return D_O_K;
306 }
307
308 bool is_reserved_key(int c)
309 {
310 switch(c)
311 {
312 case KEY_ESC:
313 return true;
314 }
315 return false;
316 }
317 bool is_reserved_keycombo(int c, int modflag)
318 {
319 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
320 return true;
321 return false;
322 }
323 bool checkcheat(Cheat cheat)
324 {
325 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
326 return true; //Main key pressed
327 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
328 return true; //Alt key pressed
329 return false;
330 }
331 259 void load_default_cheatkeys()
332 {
333 259 memset(cheatkeys, 0, sizeof(cheatkeys));
334 259 cheatkeys[Cheat::Life][0] = KEY_H;
335 259 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
336 259 cheatkeys[Cheat::Magic][0] = KEY_M;
337 259 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
338 259 cheatkeys[Cheat::Rupies][0] = KEY_R;
339 259 cheatkeys[Cheat::Bombs][0] = KEY_B;
340 259 cheatkeys[Cheat::Arrows][0] = KEY_A;
341 259 cheatkeys[Cheat::Clock][0] = KEY_I;
342 259 cheatkeys[Cheat::Walls][0] = KEY_F11;
343 259 cheatkeys[Cheat::Fast][0] = KEY_Q;
344 259 cheatkeys[Cheat::Light][0] = KEY_L;
345 259 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
346 259 cheatkeys[Cheat::Kill][0] = KEY_K;
347 259 cheatkeys[Cheat::GoTo][0] = KEY_G;
348 259 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
349 259 cheatkeys[Cheat::ShowL0][0] = KEY_0;
350 259 cheatkeys[Cheat::ShowL1][0] = KEY_1;
351 259 cheatkeys[Cheat::ShowL2][0] = KEY_2;
352 259 cheatkeys[Cheat::ShowL3][0] = KEY_3;
353 259 cheatkeys[Cheat::ShowL4][0] = KEY_4;
354 259 cheatkeys[Cheat::ShowL5][0] = KEY_5;
355 259 cheatkeys[Cheat::ShowL6][0] = KEY_6;
356 259 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
357 259 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
358 259 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
359 259 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
360 259 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
361 259 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
362 259 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
363 259 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
364 259 }
365
366 static bool loaded_game_configs;
367
368 259 void load_game_configs()
369 {
370 259 loaded_game_configs = true;
371 259 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"modules/classic.zmod"));
372 259 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
373 259 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
374 259 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
375 259 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
376 259 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
377 259 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
378 259 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
379 259 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
380 259 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
381 259 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
382 259 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
383 259 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
384 259 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
385 259 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
386
387 //cheat modifier keya
388 259 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
389 259 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
390 259 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
391 259 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
392
393 //cheat keys
394 259 load_default_cheatkeys();
395 char buf[256];
396
2/2
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 9324 times.
9583 for(size_t q = 1; q < Cheat::Last; ++q)
397 {
398
1/2
✓ Branch 0 taken 9324 times.
✗ Branch 1 not taken.
9324 if(!bindable_cheat((Cheat)q)) continue;
399 9324 std::string cheatname = cheat_to_string((Cheat)q);
400
1/2
✓ Branch 0 taken 9324 times.
✗ Branch 1 not taken.
9324 util::lowerstr(cheatname);
401 9324 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
402
1/2
✓ Branch 0 taken 9324 times.
✗ Branch 1 not taken.
9324 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
403 9324 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
404
1/2
✓ Branch 0 taken 9324 times.
✗ Branch 1 not taken.
9324 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
405 9324 }
406
407
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
408 joystick_index = 0;
409
410 259 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
411 259 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
412 259 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
413 259 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
414 259 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
415 259 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
416 259 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
417 259 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
418 259 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
419 259 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
420
421 259 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
422 259 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
423 259 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
424 259 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
425
426 259 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
427 259 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
428 259 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
429 259 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
430 259 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
431 259 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
432 259 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
433 259 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
434 259 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
435 259 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
436 259 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
437
438 259 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
439 259 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
440 259 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
441 259 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
442
443 259 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
444
445 259 midi_volume = zc_get_config(sfx_sect,"midi",255);
446 259 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
447 259 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
448 259 pan_style = zc_get_config(sfx_sect,"pan",1);
449 259 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
450 259 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
451 259 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
452 259 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
453 259 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
454 259 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
455 259 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
456 259 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
457 #ifdef __EMSCRIPTEN__
458 if (em_is_mobile()) NameEntryMode = 2;
459 #endif
460 259 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
461 259 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
462 259 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
463 259 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
464 259 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
465 259 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
466
467 259 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
468 259 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
469 259 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
470 259 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
471 259 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
472 259 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
473 259 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
474
475 259 loadlast = zc_get_config(cfg_sect,"load_last",0);
476
477 259 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
478
479 259 info_opacity = zc_get_config("zc","debug_info_opacity",255);
480 #ifdef _WIN32
481 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
482 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
483 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
484
485 // This one's for Aero
486 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
487
488 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
489 #else //UNIX
490 259 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
491 259 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
492 #endif
493 259 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
494 259 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
495
496 259 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
497 259 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
498 259 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
499 259 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
500 259 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
501 259 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
502 259 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
503 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
504 259 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
505 259 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
506 259 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
507 259 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
508 259 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
509 259 }
510
511 void save_control_configs(bool kb)
512 {
513 if(kb)
514 {
515 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
516 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
518 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
519
520 if (!replay_is_replaying())
521 {
522 zc_set_config(ctrl_sect,"key_a",Akey);
523 zc_set_config(ctrl_sect,"key_b",Bkey);
524 zc_set_config(ctrl_sect,"key_s",Skey);
525 zc_set_config(ctrl_sect,"key_l",Lkey);
526 zc_set_config(ctrl_sect,"key_r",Rkey);
527 zc_set_config(ctrl_sect,"key_p",Pkey);
528 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
529 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
530 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
531 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
532 zc_set_config(ctrl_sect,"key_up", DUkey);
533 zc_set_config(ctrl_sect,"key_down", DDkey);
534 zc_set_config(ctrl_sect,"key_left", DLkey);
535 zc_set_config(ctrl_sect,"key_right",DRkey);
536 }
537 }
538 else
539 {
540 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
541 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
542 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
543 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
544 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
545 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
546 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
547 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
548 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
549 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
550 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
551 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
552 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
553 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
554
555 zc_set_config(ctrl_sect,"btn_a",Abtn);
556 zc_set_config(ctrl_sect,"btn_b",Bbtn);
557 zc_set_config(ctrl_sect,"btn_s",Sbtn);
558 zc_set_config(ctrl_sect,"btn_m",Mbtn);
559 zc_set_config(ctrl_sect,"btn_l",Lbtn);
560 zc_set_config(ctrl_sect,"btn_r",Rbtn);
561 zc_set_config(ctrl_sect,"btn_p",Pbtn);
562 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
563 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
564 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
565 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
566
567 zc_set_config(ctrl_sect,"btn_up",DUbtn);
568 zc_set_config(ctrl_sect,"btn_down",DDbtn);
569 zc_set_config(ctrl_sect,"btn_left",DLbtn);
570 zc_set_config(ctrl_sect,"btn_right",DRbtn);
571 }
572 }
573
574 void save_cheatkeys()
575 {
576 char buf[256];
577 for(size_t q = 1; q < Cheat::Last; ++q)
578 {
579 if(!bindable_cheat((Cheat)q)) continue;
580 std::string cheatname = cheat_to_string((Cheat)q);
581 util::lowerstr(cheatname);
582 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
583 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
584 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
585 if(cheatkeys[q][1])
586 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
587 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
588 }
589 }
590
591 259 void save_game_configs()
592 {
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (!loaded_game_configs) return;
594
595 259 packfile_password("");
596
597 259 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
598
599
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
259 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
600 {
601 int o_window_x, o_window_y;
602 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
603 zc_set_config(cfg_sect,"window_x",o_window_x);
604 zc_set_config(cfg_sect,"window_y",o_window_y);
605 }
606
607
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
259 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
608 {
609 window_width = al_get_display_width(all_get_display());
610 window_height = al_get_display_height(all_get_display());
611 zc_set_config(cfg_sect,"window_width",window_width);
612 zc_set_config(cfg_sect,"window_height",window_height);
613 }
614
615 259 zc_set_config(cfg_sect,"load_last",loadlast);
616 259 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
617
618 259 flush_config_file();
619 #ifdef __EMSCRIPTEN__
620 em_sync_fs();
621 #endif
622 259 }
623
624 //----------------------------------------------------------------
625
626 // Timers
627
628 43568 void fps_callback()
629 {
630 43568 lastfps=framecnt;
631 43568 framecnt=0;
632 43568 }
633
634 END_OF_FUNCTION(fps_callback)
635
636 259 int32_t Z_init_timers()
637 {
638 static bool didit = false;
639 const static char *err_str = "Couldn't allocate timer";
640 259 err_str = err_str; //Unused variable warning
641
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if(didit)
643 return 1;
644
645 259 didit = true;
646
647 LOCK_VARIABLE(lastfps);
648 LOCK_VARIABLE(framecnt);
649 LOCK_FUNCTION(fps_callback);
650
651
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
652 return 0;
653
654 259 return 1;
655 259 }
656
657 259 void Z_remove_timers()
658 {
659 259 remove_int(fps_callback);
660 259 }
661
662 //----------------------------------------------------------------
663
664 void go()
665 {
666 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
667 }
668
669 void comeback()
670 {
671 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
672 }
673
674 void dump_pal(BITMAP *dest)
675 {
676 for(int32_t i=0; i<256; i++)
677 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
678 }
679
680 //----------------------------------------------------------------
681
682 int game_mouse_index = ZCM_BLANK;
683 static bool system_mouse = false;
684 110 bool sys_mouse()
685 {
686 110 system_mouse = true;
687 110 return MouseSprite::set(ZCM_NORMAL);
688 }
689 1507 bool game_mouse()
690 {
691 1507 system_mouse = false;
692 1507 return MouseSprite::set(game_mouse_index);
693 }
694 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
695 {
696 if(!bmp)
697 return;
698 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
699 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
700 if(bmp->w == scaledw && bmp->h == scaledh)
701 user_scale = false;
702 if(user_scale || sys_recolor)
703 {
704 if(!user_scale) scale = 1;
705 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
706 if(user_scale)
707 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
708 else
709 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
710 if(sys_recolor)
711 recolor_mouse(tmpbmp);
712 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
713 destroy_bitmap(tmpbmp);
714 }
715 else
716 {
717 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
718 }
719 }
720
721 //Handles converting the mouse sprite from the .dat file
722 void recolor_mouse(BITMAP* bmp)
723 {
724 for(int32_t x = 0; x < bmp->w; ++x)
725 {
726 for(int32_t y = 0; y < bmp->h; ++y)
727 {
728 int32_t color = getpixel(bmp, x, y);
729 switch(color)
730 {
731 case dvc(1):
732 color = jwin_pal[jcCURSORMISC];
733 break;
734 case dvc(2):
735 color = jwin_pal[jcCURSOROUTLINE];
736 break;
737 case dvc(3):
738 color = jwin_pal[jcCURSORLIGHT];
739 break;
740 case dvc(5):
741 color = jwin_pal[jcCURSORDARK];
742 break;
743 default:
744 continue;
745 }
746 putpixel(bmp, x, y, color);
747 }
748 }
749 }
750 void load_mouse()
751 {
752 PALETTE pal;
753 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
754 if (!cursor_bitmap)
755 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
756
757 enter_sys_pal();
758 MouseSprite::set(-1);
759 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
760 int32_t sz = 16*scale;
761 for(int32_t j = 0; j < 1; ++j)
762 {
763 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
764 if(zcmouse[j])
765 destroy_bitmap(zcmouse[j]);
766 zcmouse[j] = create_bitmap_ex(8,sz,sz);
767 clear_bitmap(zcmouse[j]);
768 clear_bitmap(tmpbmp);
769 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
770 recolor_mouse(tmpbmp);
771 if(sz!=16)
772 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
773 else
774 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
775 destroy_bitmap(tmpbmp);
776 }
777 if(!hw_palette) hw_palette = &RAMpal;
778 zc_set_palette(*hw_palette);
779
780 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
781 clear_bitmap(blankmouse);
782
783 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
784 MouseSprite::assign(ZCM_BLANK, blankmouse);
785 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
786
787 //Reload the mouse
788 if(system_mouse)
789 sys_mouse();
790 else game_mouse();
791
792 destroy_bitmap(blankmouse);
793 destroy_bitmap(cursor_bitmap);
794 exit_sys_pal();
795 }
796
797 // sets the video mode and initializes the palette and mouse sprite
798 259 bool game_vid_mode(int32_t mode,int32_t wait)
799 {
800
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if (is_headless())
801 259 return true;
802
803 extern int zq_screen_w, zq_screen_h;
804 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
805 {
806 return false;
807 }
808
809 scrx = (resx-320)>>1;
810 scry = (resy-240)>>1;
811 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
812 zcmouse[q] = NULL;
813 load_mouse();
814
815 for(int32_t i=240; i<256; i++)
816 RAMpal[i]=pal_gui[i];
817
818 zc_set_palette(RAMpal);
819 clear_to_color(screen,BLACK);
820
821 rest(wait);
822 return true;
823 259 }
824
825 267 void null_quest()
826 {
827
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 std::string title_assets_path = "modules/classic/title_gfx.dat";
828
2/4
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 267 times.
267 if (get_last_loaded_qstpath() == title_assets_path)
829 return;
830
831 byte skip_flags[4];
832
2/2
✓ Branch 0 taken 267 times.
✓ Branch 1 taken 6942 times.
7209 for (int i = 0; i < skip_max; i++)
833
1/2
✓ Branch 0 taken 6942 times.
✗ Branch 1 not taken.
6942 set_bit(skip_flags, i, 1);
834
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 set_bit(skip_flags, skip_tiles, 0);
835
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 set_bit(skip_flags, skip_csets, 0);
836
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
837
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
838 267 sfxdat = 1;
839 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
840 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
841 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
842 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 267 times.
267 }
844
845 267 void init_NES_mode()
846 {
847 267 null_quest();
848 267 }
849
850 //----------------------------------------------------------------
851
852 qword trianglelines[16]=
853 {
854 0x0000000000000000ULL,
855 0xFD00000000000000ULL,
856 0xFDFD000000000000ULL,
857 0xFDFDFD0000000000ULL,
858 0xFDFDFDFD00000000ULL,
859 0xFDFDFDFDFD000000ULL,
860 0xFDFDFDFDFDFD0000ULL,
861 0xFDFDFDFDFDFDFD00ULL,
862 0xFDFDFDFDFDFDFDFDULL,
863 0x00FDFDFDFDFDFDFDULL,
864 0x0000FDFDFDFDFDFDULL,
865 0x000000FDFDFDFDFDULL,
866 0x00000000FDFDFDFDULL,
867 0x0000000000FDFDFDULL,
868 0x000000000000FDFDULL,
869 0x00000000000000FDULL,
870 };
871
872 word screen_triangles[28][32];
873
874 // the ULL suffixes are to prevent this warning:
875 // warning: integer constant is too large for "int32_t" type
876
877 qword triangles[4][16][8]= //[direction][value][line]
878 {
879 {
880 {
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL,
888 0x0000000000000000ULL
889 },
890 {
891 0xFD00000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL,
898 0x0000000000000000ULL
899 },
900 {
901 0xFDFD000000000000ULL,
902 0xFD00000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL,
908 0x0000000000000000ULL
909 },
910 {
911 0xFDFDFD0000000000ULL,
912 0xFDFD000000000000ULL,
913 0xFD00000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL,
918 0x0000000000000000ULL
919 },
920 {
921 0xFDFDFDFD00000000ULL,
922 0xFDFDFD0000000000ULL,
923 0xFDFD000000000000ULL,
924 0xFD00000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL,
928 0x0000000000000000ULL
929 },
930 {
931 0xFDFDFDFDFD000000ULL,
932 0xFDFDFDFD00000000ULL,
933 0xFDFDFD0000000000ULL,
934 0xFDFD000000000000ULL,
935 0xFD00000000000000ULL,
936 0x0000000000000000ULL,
937 0x0000000000000000ULL,
938 0x0000000000000000ULL
939 },
940 {
941 0xFDFDFDFDFDFD0000ULL,
942 0xFDFDFDFDFD000000ULL,
943 0xFDFDFDFD00000000ULL,
944 0xFDFDFD0000000000ULL,
945 0xFDFD000000000000ULL,
946 0xFD00000000000000ULL,
947 0x0000000000000000ULL,
948 0x0000000000000000ULL
949 },
950 {
951 0xFDFDFDFDFDFDFD00ULL,
952 0xFDFDFDFDFDFD0000ULL,
953 0xFDFDFDFDFD000000ULL,
954 0xFDFDFDFD00000000ULL,
955 0xFDFDFD0000000000ULL,
956 0xFDFD000000000000ULL,
957 0xFD00000000000000ULL,
958 0x0000000000000000ULL
959 },
960 {
961 0xFDFDFDFDFDFDFDFDULL,
962 0xFDFDFDFDFDFDFD00ULL,
963 0xFDFDFDFDFDFD0000ULL,
964 0xFDFDFDFDFD000000ULL,
965 0xFDFDFDFD00000000ULL,
966 0xFDFDFD0000000000ULL,
967 0xFDFD000000000000ULL,
968 0xFD00000000000000ULL
969 },
970 {
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFDFDULL,
973 0xFDFDFDFDFDFDFD00ULL,
974 0xFDFDFDFDFDFD0000ULL,
975 0xFDFDFDFDFD000000ULL,
976 0xFDFDFDFD00000000ULL,
977 0xFDFDFD0000000000ULL,
978 0xFDFD000000000000ULL
979 },
980 {
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFDFDULL,
984 0xFDFDFDFDFDFDFD00ULL,
985 0xFDFDFDFDFDFD0000ULL,
986 0xFDFDFDFDFD000000ULL,
987 0xFDFDFDFD00000000ULL,
988 0xFDFDFD0000000000ULL
989 },
990 {
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFDFDULL,
995 0xFDFDFDFDFDFDFD00ULL,
996 0xFDFDFDFDFDFD0000ULL,
997 0xFDFDFDFDFD000000ULL,
998 0xFDFDFDFD00000000ULL
999 },
1000 {
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFDFDULL,
1006 0xFDFDFDFDFDFDFD00ULL,
1007 0xFDFDFDFDFDFD0000ULL,
1008 0xFDFDFDFDFD000000ULL
1009 },
1010 {
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFDFDULL,
1017 0xFDFDFDFDFDFDFD00ULL,
1018 0xFDFDFDFDFDFD0000ULL
1019 },
1020 {
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFD00ULL
1029 },
1030 {
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL,
1038 0xFDFDFDFDFDFDFDFDULL
1039 }
1040 },
1041 {
1042 {
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL,
1050 0x0000000000000000ULL
1051 },
1052 {
1053 0x00000000000000FDULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL,
1060 0x0000000000000000ULL
1061 },
1062 {
1063 0x000000000000FDFDULL,
1064 0x00000000000000FDULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL
1071 },
1072 {
1073 0x0000000000FDFDFDULL,
1074 0x000000000000FDFDULL,
1075 0x00000000000000FDULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL
1081 },
1082 {
1083 0x00000000FDFDFDFDULL,
1084 0x0000000000FDFDFDULL,
1085 0x000000000000FDFDULL,
1086 0x00000000000000FDULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL
1091 },
1092 {
1093 0x000000FDFDFDFDFDULL,
1094 0x00000000FDFDFDFDULL,
1095 0x0000000000FDFDFDULL,
1096 0x000000000000FDFDULL,
1097 0x00000000000000FDULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL
1101 },
1102 {
1103 0x0000FDFDFDFDFDFDULL,
1104 0x000000FDFDFDFDFDULL,
1105 0x00000000FDFDFDFDULL,
1106 0x0000000000FDFDFDULL,
1107 0x000000000000FDFDULL,
1108 0x00000000000000FDULL,
1109 0x0000000000000000ULL,
1110 0x0000000000000000ULL
1111 },
1112 {
1113 0x00FDFDFDFDFDFDFDULL,
1114 0x0000FDFDFDFDFDFDULL,
1115 0x000000FDFDFDFDFDULL,
1116 0x00000000FDFDFDFDULL,
1117 0x0000000000FDFDFDULL,
1118 0x000000000000FDFDULL,
1119 0x00000000000000FDULL,
1120 0x0000000000000000ULL
1121 },
1122 {
1123 0xFDFDFDFDFDFDFDFDULL,
1124 0x00FDFDFDFDFDFDFDULL,
1125 0x0000FDFDFDFDFDFDULL,
1126 0x000000FDFDFDFDFDULL,
1127 0x00000000FDFDFDFDULL,
1128 0x0000000000FDFDFDULL,
1129 0x000000000000FDFDULL,
1130 0x00000000000000FDULL
1131 },
1132 {
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0xFDFDFDFDFDFDFDFDULL,
1135 0x00FDFDFDFDFDFDFDULL,
1136 0x0000FDFDFDFDFDFDULL,
1137 0x000000FDFDFDFDFDULL,
1138 0x00000000FDFDFDFDULL,
1139 0x0000000000FDFDFDULL,
1140 0x000000000000FDFDULL
1141 },
1142 {
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0x00FDFDFDFDFDFDFDULL,
1147 0x0000FDFDFDFDFDFDULL,
1148 0x000000FDFDFDFDFDULL,
1149 0x00000000FDFDFDFDULL,
1150 0x0000000000FDFDFDULL
1151 },
1152 {
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0x00FDFDFDFDFDFDFDULL,
1158 0x0000FDFDFDFDFDFDULL,
1159 0x000000FDFDFDFDFDULL,
1160 0x00000000FDFDFDFDULL
1161 },
1162 {
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0x00FDFDFDFDFDFDFDULL,
1169 0x0000FDFDFDFDFDFDULL,
1170 0x000000FDFDFDFDFDULL
1171 },
1172 {
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0x00FDFDFDFDFDFDFDULL,
1180 0x0000FDFDFDFDFDFDULL
1181 },
1182 {
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0x00FDFDFDFDFDFDFDULL
1191 },
1192 {
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL
1201 }
1202 },
1203 {
1204 {
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL,
1212 0x0000000000000000ULL
1213 },
1214 {
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0x0000000000000000ULL,
1222 0xFD00000000000000ULL
1223 },
1224 {
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0xFD00000000000000ULL,
1232 0xFDFD000000000000ULL
1233 },
1234 {
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0x0000000000000000ULL,
1240 0xFD00000000000000ULL,
1241 0xFDFD000000000000ULL,
1242 0xFDFDFD0000000000ULL
1243 },
1244 {
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0x0000000000000000ULL,
1249 0xFD00000000000000ULL,
1250 0xFDFD000000000000ULL,
1251 0xFDFDFD0000000000ULL,
1252 0xFDFDFDFD00000000ULL
1253 },
1254 {
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0x0000000000000000ULL,
1258 0xFD00000000000000ULL,
1259 0xFDFD000000000000ULL,
1260 0xFDFDFD0000000000ULL,
1261 0xFDFDFDFD00000000ULL,
1262 0xFDFDFDFDFD000000ULL
1263 },
1264 {
1265 0x0000000000000000ULL,
1266 0x0000000000000000ULL,
1267 0xFD00000000000000ULL,
1268 0xFDFD000000000000ULL,
1269 0xFDFDFD0000000000ULL,
1270 0xFDFDFDFD00000000ULL,
1271 0xFDFDFDFDFD000000ULL,
1272 0xFDFDFDFDFDFD0000ULL
1273 },
1274 {
1275 0x0000000000000000ULL,
1276 0xFD00000000000000ULL,
1277 0xFDFD000000000000ULL,
1278 0xFDFDFD0000000000ULL,
1279 0xFDFDFDFD00000000ULL,
1280 0xFDFDFDFDFD000000ULL,
1281 0xFDFDFDFDFDFD0000ULL,
1282 0xFDFDFDFDFDFDFD00ULL
1283 },
1284 {
1285 0xFD00000000000000ULL,
1286 0xFDFD000000000000ULL,
1287 0xFDFDFD0000000000ULL,
1288 0xFDFDFDFD00000000ULL,
1289 0xFDFDFDFDFD000000ULL,
1290 0xFDFDFDFDFDFD0000ULL,
1291 0xFDFDFDFDFDFDFD00ULL,
1292 0xFDFDFDFDFDFDFDFDULL
1293 },
1294 {
1295 0xFDFD000000000000ULL,
1296 0xFDFDFD0000000000ULL,
1297 0xFDFDFDFD00000000ULL,
1298 0xFDFDFDFDFD000000ULL,
1299 0xFDFDFDFDFDFD0000ULL,
1300 0xFDFDFDFDFDFDFD00ULL,
1301 0xFDFDFDFDFDFDFDFDULL,
1302 0xFDFDFDFDFDFDFDFDULL
1303 },
1304 {
1305 0xFDFDFD0000000000ULL,
1306 0xFDFDFDFD00000000ULL,
1307 0xFDFDFDFDFD000000ULL,
1308 0xFDFDFDFDFDFD0000ULL,
1309 0xFDFDFDFDFDFDFD00ULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL,
1312 0xFDFDFDFDFDFDFDFDULL
1313 },
1314 {
1315 0xFDFDFDFD00000000ULL,
1316 0xFDFDFDFDFD000000ULL,
1317 0xFDFDFDFDFDFD0000ULL,
1318 0xFDFDFDFDFDFDFD00ULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0xFDFDFDFDFDFDFDFDULL
1323 },
1324 {
1325 0xFDFDFDFDFD000000ULL,
1326 0xFDFDFDFDFDFD0000ULL,
1327 0xFDFDFDFDFDFDFD00ULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL
1333 },
1334 {
1335 0xFDFDFDFDFDFD0000ULL,
1336 0xFDFDFDFDFDFDFD00ULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL
1343 },
1344 {
1345 0xFDFDFDFDFDFDFD00ULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL
1353 },
1354 {
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL
1363 }
1364 },
1365 {
1366 {
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL,
1374 0x0000000000000000ULL
1375 },
1376 {
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x0000000000000000ULL,
1384 0x00000000000000FDULL
1385 },
1386 {
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x00000000000000FDULL,
1394 0x000000000000FDFDULL
1395 },
1396 {
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x00000000000000FDULL,
1403 0x000000000000FDFDULL,
1404 0x0000000000FDFDFDULL
1405 },
1406 {
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x0000000000000000ULL,
1411 0x00000000000000FDULL,
1412 0x000000000000FDFDULL,
1413 0x0000000000FDFDFDULL,
1414 0x00000000FDFDFDFDULL
1415 },
1416 {
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x0000000000000000ULL,
1420 0x00000000000000FDULL,
1421 0x000000000000FDFDULL,
1422 0x0000000000FDFDFDULL,
1423 0x00000000FDFDFDFDULL,
1424 0x000000FDFDFDFDFDULL
1425 },
1426 {
1427 0x0000000000000000ULL,
1428 0x0000000000000000ULL,
1429 0x00000000000000FDULL,
1430 0x000000000000FDFDULL,
1431 0x0000000000FDFDFDULL,
1432 0x00000000FDFDFDFDULL,
1433 0x000000FDFDFDFDFDULL,
1434 0x0000FDFDFDFDFDFDULL
1435 },
1436 {
1437 0x0000000000000000ULL,
1438 0x00000000000000FDULL,
1439 0x000000000000FDFDULL,
1440 0x0000000000FDFDFDULL,
1441 0x00000000FDFDFDFDULL,
1442 0x000000FDFDFDFDFDULL,
1443 0x0000FDFDFDFDFDFDULL,
1444 0x00FDFDFDFDFDFDFDULL
1445 },
1446 {
1447 0x00000000000000FDULL,
1448 0x000000000000FDFDULL,
1449 0x0000000000FDFDFDULL,
1450 0x00000000FDFDFDFDULL,
1451 0x000000FDFDFDFDFDULL,
1452 0x0000FDFDFDFDFDFDULL,
1453 0x00FDFDFDFDFDFDFDULL,
1454 0xFDFDFDFDFDFDFDFDULL
1455 },
1456 {
1457 0x000000000000FDFDULL,
1458 0x0000000000FDFDFDULL,
1459 0x00000000FDFDFDFDULL,
1460 0x000000FDFDFDFDFDULL,
1461 0x0000FDFDFDFDFDFDULL,
1462 0x00FDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL,
1464 0xFDFDFDFDFDFDFDFDULL
1465 },
1466 {
1467 0x0000000000FDFDFDULL,
1468 0x00000000FDFDFDFDULL,
1469 0x000000FDFDFDFDFDULL,
1470 0x0000FDFDFDFDFDFDULL,
1471 0x00FDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL,
1474 0xFDFDFDFDFDFDFDFDULL
1475 },
1476 {
1477 0x00000000FDFDFDFDULL,
1478 0x000000FDFDFDFDFDULL,
1479 0x0000FDFDFDFDFDFDULL,
1480 0x00FDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL,
1484 0xFDFDFDFDFDFDFDFDULL
1485 },
1486 {
1487 0x000000FDFDFDFDFDULL,
1488 0x0000FDFDFDFDFDFDULL,
1489 0x00FDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL,
1494 0xFDFDFDFDFDFDFDFDULL
1495 },
1496 {
1497 0x0000FDFDFDFDFDFDULL,
1498 0x00FDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL
1505 },
1506 {
1507 0x00FDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL
1515 },
1516 {
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL
1525 }
1526 }
1527 };
1528
1529 int32_t black_opening_count=0;
1530 int32_t black_opening_x,black_opening_y;
1531 int32_t black_opening_shape;
1532
1533 3217 int32_t choose_opening_shape()
1534 {
1535 // First, count how many bits are set
1536 3217 int32_t numBits=0;
1537 int32_t bitCounter;
1538
1539
2/2
✓ Branch 0 taken 16085 times.
✓ Branch 1 taken 3217 times.
19302 for(int32_t i=0; i<bosMAX; i++)
1540 {
1541
2/2
✓ Branch 0 taken 12652 times.
✓ Branch 1 taken 3433 times.
16085 if(COOLSCROLL&(1<<i))
1542 3433 numBits++;
1543 16085 }
1544
1545 // Shouldn't happen...
1546
1/2
✓ Branch 0 taken 3217 times.
✗ Branch 1 not taken.
3217 if(numBits==0)
1547 return bosCIRCLE;
1548
1549 // Pick a bit
1550 3217 bitCounter=zc_rand()%numBits+1;
1551
1552
2/2
✓ Branch 0 taken 4408 times.
✓ Branch 1 taken 26 times.
4434 for(int32_t i=0; i<bosMAX; i++)
1553 {
1554 // If this bit is set, decrement the bit counter
1555
2/2
✓ Branch 0 taken 1061 times.
✓ Branch 1 taken 3347 times.
4408 if(COOLSCROLL&(1<<i))
1556 3347 bitCounter--;
1557
1558 // When the counter hits 0, return a value based on
1559 // which bit it stopped on.
1560 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1561
2/2
✓ Branch 0 taken 3191 times.
✓ Branch 1 taken 1217 times.
4408 if(bitCounter==0)
1562 3191 return i;
1563 1217 }
1564
1565 // Shouldn't be necessary, but the compiler might complain, at least
1566 26 return bosCIRCLE;
1567 3217 }
1568
1569 727 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1570 {
1571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 727 times.
727 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1572
1573 727 int32_t w=256, h=224;
1574 727 int32_t blockrows=28, blockcolumns=32;
1575 727 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1576
1577
2/2
✓ Branch 0 taken 20356 times.
✓ Branch 1 taken 727 times.
21083 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1578 {
1579
2/2
✓ Branch 0 taken 651392 times.
✓ Branch 1 taken 20356 times.
671748 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1580 {
1581
2/2
✓ Branch 0 taken 269309 times.
✓ Branch 1 taken 382083 times.
651392 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1582 651392 }
1583 20356 }
1584
1585 727 black_opening_count = 66;
1586 727 black_opening_x = x;
1587 727 black_opening_y = y;
1588 727 lensclk = 0;
1589 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1590
1591
1592
1/2
✓ Branch 0 taken 727 times.
✗ Branch 1 not taken.
727 if(black_opening_shape == bosFADEBLACK)
1593 {
1594 refreshTints();
1595 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1596 }
1597
2/2
✓ Branch 0 taken 723 times.
✓ Branch 1 taken 4 times.
727 if(wait)
1598 {
1599 4 FFCore.warpScriptCheck();
1600
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 264 times.
268 for(int32_t i=0; i<66; i++)
1601 {
1602 264 draw_screen(tmpscr);
1603 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1604 264 advanceframe(true);
1605
1606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if(Quit)
1607 {
1608 break;
1609 }
1610 264 }
1611 4 }
1612 727 }
1613
1614 2490 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1615 {
1616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2490 times.
2490 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1617
1618 2490 int32_t w=256, h=224;
1619 2490 int32_t blockrows=28, blockcolumns=32;
1620 2490 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1621
1622
2/2
✓ Branch 0 taken 69720 times.
✓ Branch 1 taken 2490 times.
72210 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1623 {
1624
2/2
✓ Branch 0 taken 2231040 times.
✓ Branch 1 taken 69720 times.
2300760 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1625 {
1626
2/2
✓ Branch 0 taken 1100154 times.
✓ Branch 1 taken 1130886 times.
2231040 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1627 2231040 }
1628 69720 }
1629
1630 2490 black_opening_count = -66;
1631 2490 black_opening_x = x;
1632 2490 black_opening_y = y;
1633 2490 lensclk = 0;
1634
1/2
✓ Branch 0 taken 2490 times.
✗ Branch 1 not taken.
2490 if(black_opening_shape == bosFADEBLACK)
1635 {
1636 refreshTints();
1637 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1638 }
1639
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 2123 times.
2490 if(wait)
1640 {
1641 2123 FFCore.warpScriptCheck();
1642
2/2
✓ Branch 0 taken 2122 times.
✓ Branch 1 taken 140121 times.
142243 for(int32_t i=0; i<66; i++)
1643 {
1644 140121 draw_screen(tmpscr);
1645 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1646 140121 advanceframe(true);
1647
1648
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 140120 times.
140121 if(Quit)
1649 {
1650 1 break;
1651 }
1652 140120 }
1653 2123 }
1654 2490 }
1655
1656 211611 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1657 {
1658 211611 clear_to_color(tmp_scr,BLACK);
1659 211611 int32_t w=256, h=224;
1660
1661
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 20262 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 181053 times.
211611 switch(black_opening_shape)
1662 {
1663 case bosOVAL:
1664 {
1665 9636 double new_w=(w/2)+abs(w/2-x);
1666 9636 double new_h=(h/2)+abs(h/2-y);
1667 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1668 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1669 9636 break;
1670 }
1671
1672 case bosTRIANGLE:
1673 {
1674 660 double new_w=(w/2)+abs(w/2-x);
1675 660 double new_h=(h/2)+abs(h/2-y);
1676 660 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1677 660 double P2= (PI/2);
1678 660 double P23=(2*PI/3);
1679 660 double P43=(4*PI/3);
1680 660 double Pa= (-4*PI*a/(3*max_a));
1681 660 double angle=P2+Pa;
1682 660 double a0=angle;
1683 660 double a2=angle+P23;
1684 660 double a4=angle+P43;
1685 1320 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1686 660 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1687 660 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1688 0);
1689 660 break;
1690 }
1691
1692 case bosSMAS:
1693 {
1694
2/2
✓ Branch 0 taken 7194 times.
✓ Branch 1 taken 13068 times.
20262 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1695
1696
2/2
✓ Branch 0 taken 567336 times.
✓ Branch 1 taken 20262 times.
587598 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1697 {
1698
2/2
✓ Branch 0 taken 4538688 times.
✓ Branch 1 taken 567336 times.
5106024 for(int32_t linerow=0; linerow<8; ++linerow)
1699 {
1700 4538688 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1701
1702
2/2
✓ Branch 0 taken 145238016 times.
✓ Branch 1 taken 4538688 times.
149776704 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1703 {
1704 435714048 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1705
6/6
✓ Branch 0 taken 104912184 times.
✓ Branch 1 taken 40325832 times.
✓ Branch 2 taken 95821040 times.
✓ Branch 3 taken 49416976 times.
✓ Branch 4 taken 55495208 times.
✓ Branch 5 taken 40325832 times.
145238016 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1706 145238016 [linerow];
1707 145238016 ++triangleline;
1708
1709
2/2
✓ Branch 0 taken 127083264 times.
✓ Branch 1 taken 18154752 times.
145238016 if(linerow==0)
1710 {
1711 18154752 }
1712 145238016 }
1713 4538688 }
1714 567336 }
1715
1716 20262 break;
1717 }
1718
1719 case bosFADEBLACK:
1720 {
1721 if(black_opening_count<0)
1722 {
1723 black_fade(zc_min(-black_opening_count,63));
1724 }
1725 else if(black_opening_count>0)
1726 {
1727 black_fade(63-zc_max(black_opening_count-3,0));
1728 }
1729 else black_fade(0);
1730 return; //no blitting from tmp_scr!
1731 }
1732
1733 181053 case bosCIRCLE:
1734 default:
1735 {
1736 181053 double new_w=(w/2)+abs(w/2-x);
1737 181053 double new_h=(h/2)+abs(h/2-y);
1738 181053 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1739 //circlefill(tmp_scr,x,y,a<<3,0);
1740 181053 circlefill(tmp_scr,x,y,r,0);
1741 181053 break;
1742 }
1743 }
1744
1745 211611 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1746 211611 }
1747
1748 // fadeamnt is 0-63
1749 void black_fade(int32_t fadeamnt)
1750 {
1751 fadeamnt = _rgb_scale_6[fadeamnt];
1752 for(int32_t i=0; i < 0xEF; i++)
1753 {
1754 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1755 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1756 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1757 }
1758
1759 refreshpal = true;
1760 }
1761
1762 //----------------------------------------------------------------
1763
1764 197901339 bool item_disabled(int32_t item) //is this item disabled?
1765 {
1766
2/2
✓ Branch 0 taken 13914587 times.
✓ Branch 1 taken 183986752 times.
197901339 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1767 }
1768
1769 15436483 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1770 {
1771
2/2
✓ Branch 0 taken 188072 times.
✓ Branch 1 taken 15248411 times.
15436483 if(current_item(item_type, true) >=item)
1772 {
1773 188072 return true;
1774 }
1775
1776 15248411 return false;
1777 15436483 }
1778
1779 48034154 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1780 {
1781
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4372065 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4901587 times.
✓ Branch 6 taken 28673931 times.
✓ Branch 7 taken 9892117 times.
✓ Branch 8 taken 194454 times.
48034154 switch(item_type)
1782 {
1783 case itype_bomb:
1784 case itype_sbomb:
1785 {
1786 int32_t itemid = getItemID(itemsbuf, item_type, it);
1787
1788 if(itemid == -1)
1789 return false;
1790
1791 return (game->get_item(itemid));
1792 }
1793
1794 case itype_clock:
1795 {
1796 4372065 int32_t itemid = getItemID(itemsbuf, item_type, it);
1797
1798
2/4
✓ Branch 0 taken 4372065 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4372065 times.
✗ Branch 3 not taken.
4372065 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1799 return (game->get_item(itemid));
1800 4372065 return Hero.getClock()?1:0;
1801 }
1802
1803 case itype_key:
1804 return (game->get_keys()>0);
1805
1806 case itype_magiccontainer:
1807 return (game->get_maxmagic()>=game->get_mp_per_block());
1808
1809 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1810 {
1811
2/3
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4580371 times.
4901587 switch(it)
1812 {
1813 case -2:
1814 {
1815 for(int32_t i=0; i<MAXLEVELS; i++)
1816 {
1817 if(game->lvlitems[i]&liTRIFORCE)
1818 {
1819 return true;
1820 }
1821 }
1822
1823 return false;
1824 }
1825
1826 case -1:
1827 4580371 return (game->lvlitems[dlevel]&liTRIFORCE);
1828
1829 default:
1830
2/4
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321216 times.
321216 if(it>=0&&it<MAXLEVELS)
1831 {
1832 321216 return (game->lvlitems[it]&liTRIFORCE);
1833 }
1834
1835 break;
1836 }
1837
1838 return 0;
1839 }
1840
1841 case itype_map: //it: -2=any, -1=current level, other=that level
1842 {
1843
2/3
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28133529 times.
28673931 switch(it)
1844 {
1845 case -2:
1846 {
1847 for(int32_t i=0; i<MAXLEVELS; i++)
1848 {
1849 if(game->lvlitems[i]&liMAP)
1850 {
1851 return true;
1852 }
1853 }
1854
1855 return false;
1856 }
1857
1858 case -1:
1859 28133529 return (game->lvlitems[dlevel]&liMAP)!=0;
1860
1861 default:
1862
2/4
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 540402 times.
540402 if(it>=0&&it<MAXLEVELS)
1863 {
1864 540402 return (game->lvlitems[it]&liMAP)!=0;
1865 }
1866
1867 break;
1868 }
1869
1870 return 0;
1871 }
1872
1873 case itype_compass: //it: -2=any, -1=current level, other=that level
1874 {
1875
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9892117 times.
9892117 switch(it)
1876 {
1877 case -2:
1878 {
1879 for(int32_t i=0; i<MAXLEVELS; i++)
1880 {
1881 if(game->lvlitems[i]&liCOMPASS)
1882 {
1883 return true;
1884 }
1885 }
1886
1887 return false;
1888 }
1889
1890 case -1:
1891 9892117 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1892
1893 default:
1894 if(it>=0&&it<MAXLEVELS)
1895 {
1896 return (game->lvlitems[it]&liCOMPASS)!=0;
1897 }
1898
1899 break;
1900 }
1901 return 0;
1902 }
1903
1904 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1905 {
1906
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 194454 times.
194454 switch(it)
1907 {
1908 case -2:
1909 {
1910 for(int32_t i=0; i<MAXLEVELS; i++)
1911 {
1912 if(game->lvlitems[i]&liBOSSKEY)
1913 {
1914 return true;
1915 }
1916 }
1917
1918 return false;
1919 }
1920
1921 case -1:
1922 194454 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1923
1924 default:
1925 if(it>=0&&it<MAXLEVELS)
1926 {
1927 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1928 }
1929 break;
1930 }
1931 return 0;
1932 }
1933
1934 default:
1935 int32_t itemid = getItemID(itemsbuf, item_type, it);
1936
1937 if(itemid == -1)
1938 return false;
1939
1940 return game->get_item(itemid);
1941 }
1942 48034154 }
1943
1944 149100897 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1945 {
1946
9/9
✓ Branch 0 taken 4372065 times.
✓ Branch 1 taken 114124377 times.
✓ Branch 2 taken 4372065 times.
✓ Branch 3 taken 4372065 times.
✓ Branch 4 taken 4372065 times.
✓ Branch 5 taken 4372065 times.
✓ Branch 6 taken 4372065 times.
✓ Branch 7 taken 4372065 times.
✓ Branch 8 taken 4372065 times.
149100897 switch(item_type)
1947 {
1948 case itype_clock:
1949 {
1950 4372065 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1951
1952
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4372065 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4372065 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1953 return itemsbuf[maxid].fam_type;
1954
1955 4372065 return has_item(itype_clock,1) ? 1 : 0;
1956 }
1957
1958 case itype_key:
1959 4372065 return game->get_keys();
1960
1961 case itype_lkey:
1962 4372065 return game->lvlkeys[get_dlevel()];
1963
1964 case itype_magiccontainer:
1965 4372065 return game->get_maxmagic()/game->get_mp_per_block();
1966
1967 case itype_triforcepiece:
1968 {
1969 4372065 int count=0;
1970
1971
2/2
✓ Branch 0 taken 2238497280 times.
✓ Branch 1 taken 4372065 times.
2242869345 for(int i=0; i<MAXLEVELS; i++)
1972 {
1973 2238497280 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1974 2238497280 }
1975
1976 4372065 return count;
1977 }
1978
1979 case itype_map:
1980 {
1981 4372065 int count=0;
1982
1983
2/2
✓ Branch 0 taken 2238497280 times.
✓ Branch 1 taken 4372065 times.
2242869345 for(int i=0; i<MAXLEVELS; i++)
1984 {
1985 2238497280 count+=(game->lvlitems[i]&liMAP)?1:0;
1986 2238497280 }
1987
1988 4372065 return count;
1989 }
1990
1991 case itype_compass:
1992 {
1993 4372065 int count=0;
1994
1995
2/2
✓ Branch 0 taken 2238497280 times.
✓ Branch 1 taken 4372065 times.
2242869345 for(int i=0; i<MAXLEVELS; i++)
1996 {
1997 2238497280 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1998 2238497280 }
1999
2000 4372065 return count;
2001 }
2002
2003 case itype_bosskey:
2004 {
2005 4372065 int count=0;
2006
2007
2/2
✓ Branch 0 taken 2238497280 times.
✓ Branch 1 taken 4372065 times.
2242869345 for(int i=0; i<MAXLEVELS; i++)
2008 {
2009 2238497280 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2010 2238497280 }
2011
2012 4372065 return count;
2013 }
2014
2015 default:
2016 114124377 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2017
2018
2/2
✓ Branch 0 taken 81099337 times.
✓ Branch 1 taken 33025040 times.
114124377 if(maxid == -1)
2019 81099337 return 0;
2020
2021 33025040 return itemsbuf[maxid].fam_type;
2022 }
2023 149100897 }
2024
2025 349 std::map<int32_t, int32_t> itemcache;
2026 349 std::map<int32_t, int32_t> itemcache_cost;
2027
2028 void removeFromItemCache(int32_t itemclass)
2029 {
2030 itemcache.erase(itemclass);
2031 itemcache_cost.erase(itemclass);
2032 cache_tile_mod_clear();
2033 }
2034
2035 12388309 void flushItemCache(bool justcost)
2036 {
2037 12388309 itemcache_cost.clear();
2038
2/2
✓ Branch 0 taken 12321978 times.
✓ Branch 1 taken 66331 times.
12388309 if(!justcost)
2039 66331 itemcache.clear();
2040
2/2
✓ Branch 0 taken 5825976 times.
✓ Branch 1 taken 6496002 times.
12321978 else if(replay_version_check(0,19))
2041 5825976 return;
2042
2043 6562333 cache_tile_mod_clear();
2044
2045 //also fix the active subscreen if items were deleted -DD
2046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6562333 times.
6562333 if(game != NULL)
2047 {
2048 6562333 verifyBothWeapons();
2049 6562333 refresh_subscr_items();
2050 6562333 }
2051 12388309 }
2052
2053 // This is used often, so it should be as direct as possible.
2054 2945958898 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2055 {
2056 2945958898 bool use_cost_cache = replay_version_check(19);
2057
2/2
✓ Branch 0 taken 2821769731 times.
✓ Branch 1 taken 124189167 times.
2945958898 if(jinx_check)
2058 {
2059 //special case for shields...
2060
3/4
✓ Branch 0 taken 39600557 times.
✓ Branch 1 taken 84588610 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39600557 times.
124189167 if (itemtype == itype_shield && !HeroShieldClk())
2061 39600557 jinx_check = false;
2062
4/4
✓ Branch 0 taken 52049766 times.
✓ Branch 1 taken 32538844 times.
✓ Branch 2 taken 10855064 times.
✓ Branch 3 taken 41194702 times.
84588610 else if(!(HeroSwordClk() || HeroItemClk()))
2063 41194702 jinx_check = false; //not jinxed
2064 124189167 }
2065
4/4
✓ Branch 0 taken 103098 times.
✓ Branch 1 taken 2945855800 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 101245 times.
2945958898 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2066 2945857653 check_bunny = false;
2067
2/2
✓ Branch 0 taken 2890104480 times.
✓ Branch 1 taken 55854418 times.
2945958898 if(itemtype == itype_ring) checkmagic = true;
2068
4/4
✓ Branch 0 taken 2902564990 times.
✓ Branch 1 taken 43393908 times.
✓ Branch 2 taken 274567871 times.
✓ Branch 3 taken 23758619 times.
3244285388 if (!jinx_check && !check_bunny
2069
4/4
✓ Branch 0 taken 2902485743 times.
✓ Branch 1 taken 79247 times.
✓ Branch 2 taken 298326490 times.
✓ Branch 3 taken 2604159253 times.
2902564990 && (use_cost_cache || itemtype != itype_ring))
2070 {
2071
4/4
✓ Branch 0 taken 533277921 times.
✓ Branch 1 taken 2345449203 times.
✓ Branch 2 taken 232758434 times.
✓ Branch 3 taken 300519487 times.
2878727124 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2072 2878727124 auto res = cache.find(itemtype);
2073
2074
2/2
✓ Branch 0 taken 2735182802 times.
✓ Branch 1 taken 143544322 times.
2878727124 if(res != cache.end())
2075 2735182802 return res->second;
2076 143544322 }
2077
2078 210776096 int result = -1;
2079 210776096 int highestlevel = -1;
2080
2081
2/2
✓ Branch 0 taken 53958680576 times.
✓ Branch 1 taken 210776096 times.
54169456672 for(int i=0; i<MAXITEMS; i++)
2082 {
2083
6/6
✓ Branch 0 taken 5919657263 times.
✓ Branch 1 taken 48039023313 times.
✓ Branch 2 taken 95477352 times.
✓ Branch 3 taken 5824179911 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 95395304 times.
53958680576 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2084 {
2085
4/4
✓ Branch 0 taken 90784341 times.
✓ Branch 1 taken 4610963 times.
✓ Branch 2 taken 2425909 times.
✓ Branch 3 taken 88358432 times.
95395304 if(checkmagic && itemtype != itype_magicring)
2086
2/2
✓ Branch 0 taken 88357815 times.
✓ Branch 1 taken 617 times.
88358432 if(!checkmagiccost(i))
2087 617 continue;
2088
6/6
✓ Branch 0 taken 87820257 times.
✓ Branch 1 taken 7574430 times.
✓ Branch 2 taken 1253626 times.
✓ Branch 3 taken 6320804 times.
✓ Branch 4 taken 4128291 times.
✓ Branch 5 taken 3446139 times.
95394687 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3446139 times.
3446139 if(!(itemsbuf[i].flags & item_jinx_immune))
2090 3446139 continue;
2091
3/4
✓ Branch 0 taken 86055 times.
✓ Branch 1 taken 91862493 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 86055 times.
91948548 if(check_bunny && !checkbunny(i))
2092 86055 continue;
2093
2094
2/2
✓ Branch 0 taken 8380386 times.
✓ Branch 1 taken 83482107 times.
91862493 if(itemsbuf[i].fam_type >= highestlevel)
2095 {
2096 83482107 highestlevel = itemsbuf[i].fam_type;
2097 83482107 result=i;
2098 83482107 }
2099 91862493 }
2100 53955147765 }
2101
2102
4/4
✓ Branch 0 taken 167382188 times.
✓ Branch 1 taken 43393908 times.
✓ Branch 2 taken 79247 times.
✓ Branch 3 taken 167302941 times.
210776096 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2103 {
2104
2/2
✓ Branch 0 taken 127550005 times.
✓ Branch 1 taken 39752936 times.
167302941 if (use_cost_cache)
2105 {
2106
2/2
✓ Branch 0 taken 111817075 times.
✓ Branch 1 taken 15732930 times.
127550005 if (!checkmagic)
2107 15732930 itemcache[itemtype] = result;
2108
6/6
✓ Branch 0 taken 15732930 times.
✓ Branch 1 taken 111817075 times.
✓ Branch 2 taken 659702 times.
✓ Branch 3 taken 15073228 times.
✓ Branch 4 taken 647073 times.
✓ Branch 5 taken 12629 times.
127550005 if (checkmagic || result < 0 || checkmagiccost(result))
2109 127537376 itemcache_cost[itemtype] = result;
2110 127550005 }
2111 else
2112 {
2113 39752936 itemcache[itemtype] = result;
2114 }
2115 167302941 }
2116 210776096 return result;
2117 2945958898 }
2118
2119 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2120 2903065118 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2121 {
2122
2/4
✓ Branch 0 taken 2903065118 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2903065118 times.
2903065118 if(itype < 0 || itype >= itype_max) return -1;
2123
1/2
✓ Branch 0 taken 2903065118 times.
✗ Branch 1 not taken.
2903065118 if(game->OverrideItems[itype] > -2)
2124 {
2125 auto ovid = game->OverrideItems[itype];
2126 if(ovid < 0 || ovid >= MAXITEMS)
2127 return -1;
2128 if(itemsbuf[ovid].family == itype)
2129 {
2130 if(itype == itype_magicring)
2131 checkmagic = false;
2132 else if(itype == itype_ring)
2133 checkmagic = true;
2134
2135 if(checkmagic && !checkmagiccost(ovid))
2136 return -1;
2137
2138 if (jinx_check && !checkitem_jinx(ovid))
2139 {
2140 return -1;
2141 }
2142 return ovid;
2143 }
2144 }
2145 2903065118 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2146
2/2
✓ Branch 0 taken 81295387 times.
✓ Branch 1 taken 2821769731 times.
2903065118 if(!jinx_check) //If not already a jinx-immune-only check...
2147 {
2148 //And the player IS jinxed...
2149
2/2
✓ Branch 0 taken 2778875951 times.
✓ Branch 1 taken 42893780 times.
2821769731 if(HeroIsJinxed())
2150 {
2151 //Then do a jinx-immune-only check here
2152 42893780 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2153 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2154 //Should NOT need a compat rule, as this should always return -1 in old quests.
2155
2/2
✓ Branch 0 taken 3252908 times.
✓ Branch 1 taken 39640872 times.
42893780 if(ret2 > -1) return ret2;
2156 39640872 }
2157 2818516823 }
2158 2899812210 return ret;
2159 2903065118 }
2160
2161 46326822 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2162 {
2163 46326822 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2164
2/2
✓ Branch 0 taken 26783080 times.
✓ Branch 1 taken 19543742 times.
46326822 return (result<0) ? 0 : itemsbuf[result].power;
2165 }
2166
2167 26 int32_t heart_container_id()
2168 {
2169
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2170 {
2171
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2172 {
2173 26 return i;
2174 }
2175 728 }
2176 return -1;
2177 26 }
2178
2179 struct tilemod_cache_state_t
2180 {
2181
6/6
✓ Branch 0 taken 4371710 times.
✓ Branch 1 taken 8394716 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8394714 times.
✓ Branch 4 taken 353 times.
✓ Branch 5 taken 8394361 times.
21161142 bool operator==(const tilemod_cache_state_t&) const = default;
2182
2183 bool valid;
2184 bool bunny_clock;
2185 bool superman;
2186 int shield;
2187 };
2188 tilemod_cache_state_t tilemod_cache_state;
2189 int32_t tilemod_cache_value;
2190
2191 6563752 void cache_tile_mod_clear()
2192 {
2193 6563752 tilemod_cache_state = {false};
2194 6563752 }
2195
2196 12766426 int32_t item_tile_mod()
2197 {
2198 51065704 tilemod_cache_state_t state = {
2199 .valid = true,
2200 12766426 .bunny_clock = Hero.BunnyClock() != 0,
2201 12766426 .superman = Hero.superman,
2202 12766426 .shield = Hero.active_shield_id,
2203 };
2204
2/2
✓ Branch 0 taken 8394361 times.
✓ Branch 1 taken 4372065 times.
12766426 if (tilemod_cache_state == state)
2205 8394361 return tilemod_cache_value;
2206
2207 4372065 int32_t tile=0;
2208 4372065 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2209
4/4
✓ Branch 0 taken 3958828 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 3039600 times.
✓ Branch 3 taken 919228 times.
4372065 if(check_bombcost || game->get_bombs())
2210 {
2211 3452837 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2212
3/4
✓ Branch 0 taken 3393364 times.
✓ Branch 1 taken 59473 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3393364 times.
3452837 if(itemid > -1 && checkbunny(itemid))
2213 3393364 tile+=itemsbuf[itemid].ltm;
2214 3452837 }
2215
2216
4/4
✓ Branch 0 taken 3958828 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 928295 times.
✓ Branch 3 taken 3030533 times.
4372065 if(check_bombcost || game->get_sbombs())
2217 {
2218 1341532 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2219
3/4
✓ Branch 0 taken 928054 times.
✓ Branch 1 taken 413478 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 928054 times.
1341532 if(itemid > -1 && checkbunny(itemid))
2220 928054 tile+=itemsbuf[itemid].ltm;
2221 1341532 }
2222
2223
2/2
✓ Branch 0 taken 4367462 times.
✓ Branch 1 taken 4603 times.
4372065 if(current_item(itype_clock))
2224 {
2225 4603 int32_t itemid =
2226
2/2
✓ Branch 0 taken 4594 times.
✓ Branch 1 taken 9 times.
4603 get_qr(qr_HARDCODED_LITEM_LTMS)
2227 ? iClock
2228 9 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2229
2/4
✓ Branch 0 taken 4603 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4603 times.
4603 if(itemid > -1 && checkbunny(itemid))
2230 4603 tile+=itemsbuf[itemid].ltm;
2231 4603 }
2232
2233
2/2
✓ Branch 0 taken 3763425 times.
✓ Branch 1 taken 608640 times.
4372065 if(current_item(itype_key))
2234 {
2235 608640 int32_t itemid =
2236
1/2
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
608640 get_qr(qr_HARDCODED_LITEM_LTMS)
2237 ? iKey
2238 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2239
2/4
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 608640 times.
608640 if(itemid > -1 && checkbunny(itemid))
2240 608640 tile+=itemsbuf[itemid].ltm;
2241 608640 }
2242
2243
2/2
✓ Branch 0 taken 3871205 times.
✓ Branch 1 taken 500860 times.
4372065 if(current_item(itype_lkey))
2244 {
2245 500860 int32_t itemid =
2246
2/2
✓ Branch 0 taken 414146 times.
✓ Branch 1 taken 86714 times.
500860 get_qr(qr_HARDCODED_LITEM_LTMS)
2247 ? iLevelKey
2248 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2249
2/4
✓ Branch 0 taken 500860 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500860 times.
500860 if(itemid > -1 && checkbunny(itemid))
2250 500860 tile+=itemsbuf[itemid].ltm;
2251 500860 }
2252
2253
2/2
✓ Branch 0 taken 1537597 times.
✓ Branch 1 taken 2834468 times.
4372065 if(current_item(itype_map))
2254 {
2255 2834468 int32_t itemid =
2256
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10634 times.
2834468 get_qr(qr_HARDCODED_LITEM_LTMS)
2257 ? iMap
2258 10634 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2259
2/4
✓ Branch 0 taken 2834468 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834468 times.
2834468 if(itemid > -1 && checkbunny(itemid))
2260 2834468 tile+=itemsbuf[itemid].ltm;
2261 2834468 }
2262
2263
2/2
✓ Branch 0 taken 2060076 times.
✓ Branch 1 taken 2311989 times.
4372065 if(current_item(itype_compass))
2264 {
2265 2311989 int32_t itemid =
2266
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2267 ? iCompass
2268 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2269
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2270 2311989 tile+=itemsbuf[itemid].ltm;
2271 2311989 }
2272
2273
2/2
✓ Branch 0 taken 1285649 times.
✓ Branch 1 taken 3086416 times.
4372065 if(current_item(itype_bosskey))
2274 {
2275 3086416 int32_t itemid =
2276
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2277 ? iBossKey
2278 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2279
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2280 3086416 tile+=itemsbuf[itemid].ltm;
2281 3086416 }
2282
2283
2/2
✓ Branch 0 taken 48211 times.
✓ Branch 1 taken 4323854 times.
4372065 if(current_item(itype_magiccontainer))
2284 {
2285 4323854 int32_t itemid =
2286
2/2
✓ Branch 0 taken 3893055 times.
✓ Branch 1 taken 430799 times.
4323854 get_qr(qr_HARDCODED_LITEM_LTMS)
2287 ? iMagicC
2288 430799 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2289
3/4
✓ Branch 0 taken 4323854 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4323837 times.
4323854 if(itemid > -1 && checkbunny(itemid))
2290 4323837 tile+=itemsbuf[itemid].ltm;
2291 4323854 }
2292
2293
2/2
✓ Branch 0 taken 1302879 times.
✓ Branch 1 taken 3069186 times.
4372065 if(current_item(itype_triforcepiece))
2294 {
2295 3069186 int32_t itemid =
2296
1/2
✓ Branch 0 taken 3069186 times.
✗ Branch 1 not taken.
3069186 get_qr(qr_HARDCODED_LITEM_LTMS)
2297 ? iTriforce
2298 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2299
2/4
✓ Branch 0 taken 3069186 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3069186 times.
3069186 if(itemid > -1 && checkbunny(itemid))
2300 3069186 tile+=itemsbuf[itemid].ltm;
2301 3069186 }
2302
2303
2/2
✓ Branch 0 taken 2238497280 times.
✓ Branch 1 taken 4372065 times.
2242869345 for(int32_t i=0; i<itype_max; i++)
2304 {
2305
2/2
✓ Branch 0 taken 2017846784 times.
✓ Branch 1 taken 220650496 times.
2238497280 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2306 {
2307
2/2
✓ Branch 0 taken 4309580 times.
✓ Branch 1 taken 216340916 times.
220650496 switch(i)
2308 {
2309 case itype_bomb:
2310 case itype_sbomb:
2311 case itype_clock:
2312 case itype_key:
2313 case itype_lkey:
2314 case itype_map:
2315 case itype_compass:
2316 case itype_bosskey:
2317 case itype_magiccontainer:
2318 case itype_triforcepiece:
2319 4309580 continue; //already handled
2320 }
2321 216340916 }
2322 2234187700 int32_t itemid = current_item_id(i,false);
2323
2/2
✓ Branch 0 taken 2229815635 times.
✓ Branch 1 taken 4372065 times.
2234187700 if(i == itype_shield)
2324 4372065 itemid = getCurrentShield(false);
2325
2326
4/4
✓ Branch 0 taken 114055091 times.
✓ Branch 1 taken 2120132609 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 114055090 times.
2234187700 if(itemid < 0 || !checkbunny(itemid))
2327 2120132610 continue;
2328
2329 114055090 itemdata const& itm = itemsbuf[itemid];
2330
2331
2/2
✓ Branch 0 taken 110392519 times.
✓ Branch 1 taken 3662571 times.
114055090 switch(itm.family)
2332 {
2333 case itype_shield:
2334
1/2
✓ Branch 0 taken 3662571 times.
✗ Branch 1 not taken.
3662571 if(itm.flags & item_flag9) //active shield
2335 {
2336 if(!usingActiveShield(itemid))
2337 {
2338 tile+=itm.misc6; //'Inactive PTM'
2339 continue;
2340 }
2341 }
2342 3662571 break;
2343 }
2344
2345 114055090 tile+=itm.ltm;
2346 114055090 }
2347
2348 4372065 tilemod_cache_value = tile;
2349 4372065 tilemod_cache_state = state;
2350 4372065 return tile;
2351 12766426 }
2352
2353 12766426 int32_t bunny_tile_mod()
2354 {
2355
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12764556 times.
12766426 if(Hero.BunnyClock())
2356 {
2357 1870 return game->get_bunny_ltm();
2358 }
2359 12764556 return 0;
2360 12766426 }
2361
2362 // Hints are drawn on a separate layer to combo reveals.
2363 20010 void draw_lens_under(BITMAP *dest, bool layer)
2364 {
2365 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2366 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2367 //Lens flag 3: Don't show armos/chest/dive items
2368 //Lens flag 4: Show Raft Paths
2369 //Lens flag 5: Show Invisible Enemies
2370
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 19554 times.
✓ Branch 2 taken 9777 times.
✓ Branch 3 taken 9777 times.
20010 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2371
2372 20010 int32_t strike_hint_table[11]=
2373 {
2374 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2375 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2376 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2377 };
2378
2379 {
2380 20010 int32_t blink_rate=flash_reduction_enabled()?6:1;
2381 20010 int32_t tempitem, tempweapon=0;
2382 20010 strike_hint=strike_hint_table[strike_hint_counter];
2383
2384
2/2
✓ Branch 0 taken 19412 times.
✓ Branch 1 taken 598 times.
20010 if(strike_hint_timer>32)
2385 {
2386 598 strike_hint_timer=0;
2387 598 strike_hint_counter=((strike_hint_counter+1)%11);
2388 598 }
2389
2390 20010 ++strike_hint_timer;
2391
2392
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 20010 times.
3541770 for(int32_t i=0; i<176; i++)
2393 {
2394 3521760 int32_t x = (i & 15) << 4;
2395 3521760 int32_t y = (i & 0xF0) + playing_field_offset;
2396 3521760 int32_t tempitemx=-16, tempitemy=-16;
2397 3521760 int32_t tempweaponx=-16, tempweapony=-16;
2398
2399
2/2
✓ Branch 0 taken 7043520 times.
✓ Branch 1 taken 3521760 times.
10565280 for(int32_t iter=0; iter<2; ++iter)
2400 {
2401 7043520 int32_t checkflag=0;
2402
2403
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 3521760 times.
7043520 if(iter==0)
2404 {
2405 3521760 checkflag=combobuf[tmpscr->data[i]].flag;
2406 3521760 }
2407 else
2408 {
2409 3521760 checkflag=tmpscr->sflag[i];
2410 }
2411
2412
2/2
✓ Branch 0 taken 7042422 times.
✓ Branch 1 taken 1098 times.
7043520 if(checkflag==mfSTRIKE)
2413 {
2414
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2415 {
2416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2417 906 }
2418 else
2419 {
2420 192 checkflag = strike_hint;
2421 }
2422 1098 }
2423
2424
21/36
✓ Branch 0 taken 6894870 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7043520 switch(checkflag)
2425 {
2426 case 0:
2427 case mfZELDA:
2428 case mfPUSHED:
2429 case mfENEMY0:
2430 case mfENEMY1:
2431 case mfENEMY2:
2432 case mfENEMY3:
2433 case mfENEMY4:
2434 case mfENEMY5:
2435 case mfENEMY6:
2436 case mfENEMY7:
2437 case mfENEMY8:
2438 case mfENEMY9:
2439 case mfSINGLE:
2440 case mfSINGLE16:
2441 case mfNOENEMY:
2442 case mfTRAP_H:
2443 case mfTRAP_V:
2444 case mfTRAP_4:
2445 case mfTRAP_LR:
2446 case mfTRAP_UD:
2447 case mfNOGROUNDENEMY:
2448 case mfNOBLOCKS:
2449 case mfSCRIPT1:
2450 case mfSCRIPT2:
2451 case mfSCRIPT3:
2452 case mfSCRIPT4:
2453 case mfSCRIPT5:
2454 case mfSCRIPT6:
2455 case mfSCRIPT7:
2456 case mfSCRIPT8:
2457 case mfSCRIPT9:
2458 case mfSCRIPT10:
2459 case mfSCRIPT11:
2460 case mfSCRIPT12:
2461 case mfSCRIPT13:
2462 case mfSCRIPT14:
2463 case mfSCRIPT15:
2464 case mfSCRIPT16:
2465 case mfSCRIPT17:
2466 case mfSCRIPT18:
2467 case mfSCRIPT19:
2468 case mfSCRIPT20:
2469 case mfPITHOLE:
2470 case mfPITFALLFLOOR:
2471 case mfLAVA:
2472 case mfICE:
2473 case mfICEDAMAGE:
2474 case mfDAMAGE1:
2475 case mfDAMAGE2:
2476 case mfDAMAGE4:
2477 case mfDAMAGE8:
2478 case mfDAMAGE16:
2479 case mfDAMAGE32:
2480 case mfFREEZEALL:
2481 case mfFREZEALLANSFFCS:
2482 case mfFREEZEFFCSOLY:
2483 case mfSCRITPTW1TRIG:
2484 case mfSCRITPTW2TRIG:
2485 case mfSCRITPTW3TRIG:
2486 case mfSCRITPTW4TRIG:
2487 case mfSCRITPTW5TRIG:
2488 case mfSCRITPTW6TRIG:
2489 case mfSCRITPTW7TRIG:
2490 case mfSCRITPTW8TRIG:
2491 case mfSCRITPTW9TRIG:
2492 case mfSCRITPTW10TRIG:
2493 case mfTROWEL:
2494 case mfTROWELNEXT:
2495 case mfTROWELSPECIALITEM:
2496 case mfSLASHPOT:
2497 case mfLIFTPOT:
2498 case mfLIFTORSLASH:
2499 case mfLIFTROCK:
2500 case mfLIFTROCKHEAVY:
2501 case mfDROPITEM:
2502 case mfSPECIALITEM:
2503 case mfDROPKEY:
2504 case mfDROPLKEY:
2505 case mfDROPCOMPASS:
2506 case mfDROPMAP:
2507 case mfDROPBOSSKEY:
2508 case mfSPAWNNPC:
2509 case mfSWITCHHOOK:
2510 case mfSIDEVIEWLADDER:
2511 case mfSIDEVIEWPLATFORM:
2512 case mfNOENEMYSPAWN:
2513 case mfENEMYALL:
2514 case mfNOMIRROR:
2515 case mfUNSAFEGROUND:
2516 case mf168:
2517 case mf169:
2518 case mf170:
2519 case mf171:
2520 case mf172:
2521 case mf173:
2522 case mf174:
2523 case mf175:
2524 case mf176:
2525 case mf177:
2526 case mf178:
2527 case mf179:
2528 case mf180:
2529 case mf181:
2530 case mf182:
2531 case mf183:
2532 case mf184:
2533 case mf185:
2534 case mf186:
2535 case mf187:
2536 case mf188:
2537 case mf189:
2538 case mf190:
2539 case mf191:
2540 case mf192:
2541 case mf193:
2542 case mf194:
2543 case mf195:
2544 case mf196:
2545 case mf197:
2546 case mf198:
2547 case mf199:
2548 case mf200:
2549 case mf201:
2550 case mf202:
2551 case mf203:
2552 case mf204:
2553 case mf205:
2554 case mf206:
2555 case mf207:
2556 case mf208:
2557 case mf209:
2558 case mf210:
2559 case mf211:
2560 case mf212:
2561 case mf213:
2562 case mf214:
2563 case mf215:
2564 case mf216:
2565 case mf217:
2566 case mf218:
2567 case mf219:
2568 case mf220:
2569 case mf221:
2570 case mf222:
2571 case mf223:
2572 case mf224:
2573 case mf225:
2574 case mf226:
2575 case mf227:
2576 case mf228:
2577 case mf229:
2578 case mf230:
2579 case mf231:
2580 case mf232:
2581 case mf233:
2582 case mf234:
2583 case mf235:
2584 case mf236:
2585 case mf237:
2586 case mf238:
2587 case mf239:
2588 case mf240:
2589 case mf241:
2590 case mf242:
2591 case mf243:
2592 case mf244:
2593 case mf245:
2594 case mf246:
2595 case mf247:
2596 case mf248:
2597 case mf249:
2598 case mf250:
2599 case mf251:
2600 case mf252:
2601 case mf253:
2602 case mf254:
2603 case mfEXTENDED:
2604 6894870 break;
2605
2606 case mfPUSHUD:
2607 case mfPUSHLR:
2608 case mfPUSH4:
2609 case mfPUSHU:
2610 case mfPUSHD:
2611 case mfPUSHL:
2612 case mfPUSHR:
2613 case mfPUSHUDNS:
2614 case mfPUSHLRNS:
2615 case mfPUSH4NS:
2616 case mfPUSHUNS:
2617 case mfPUSHDNS:
2618 case mfPUSHLNS:
2619 case mfPUSHRNS:
2620 case mfPUSHUDINS:
2621 case mfPUSHLRINS:
2622 case mfPUSH4INS:
2623 case mfPUSHUINS:
2624 case mfPUSHDINS:
2625 case mfPUSHLINS:
2626 case mfPUSHRINS:
2627
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2628
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2629 {
2630 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2631 }
2632
2633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2634
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2635 {
2636
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2637 {
2638
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2639 {
2640 case cPUSH_HEAVY:
2641 case cPUSH_HW:
2642 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2643 72 tempitemx=x, tempitemy=y;
2644
2645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2646 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2647
2648 72 break;
2649
2650 case cPUSH_HEAVY2:
2651 case cPUSH_HW2:
2652 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2653 63 tempitemx=x, tempitemy=y;
2654
2655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2656 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2657
2658 63 break;
2659 }
2660 1032 }
2661 2520 }
2662
2663 3258 break;
2664
2665 case mfWHISTLE:
2666
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2667 {
2668 tempitem=getItemID(itemsbuf,itype_whistle,1);
2669
2670 if(tempitem<0) break;
2671
2672 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2673 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2674 {
2675 tempitemx=x;
2676 tempitemy=y;
2677 }
2678
2679 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2680 }
2681
2682 2418 break;
2683
2684 //Why is this here?
2685 case mfFAIRY:
2686 case mfMAGICFAIRY:
2687 case mfALLFAIRY:
2688 if(hints)
2689 {
2690 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2691
2692 if(tempitem < 0) break;
2693
2694 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2695 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2696 {
2697 tempitemx=x;
2698 tempitemy=y;
2699 }
2700
2701 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2702 }
2703
2704 break;
2705
2706 case mfANYFIRE:
2707
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2708 {
2709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2710 252 }
2711 else
2712 {
2713 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2714
2715
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2716
2717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2718
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2719 {
2720 189 tempitemx=x;
2721 189 tempitemy=y;
2722 189 }
2723
2724 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2725 }
2726
2727 504 break;
2728
2729 case mfSTRONGFIRE:
2730 if(!hints)
2731 {
2732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2733 }
2734 else
2735 {
2736 tempitem=getItemID(itemsbuf,itype_candle,2);
2737
2738 if(tempitem<0) break;
2739
2740 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2741 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2742 {
2743 tempitemx=x;
2744 tempitemy=y;
2745 }
2746
2747 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2748 }
2749
2750 break;
2751
2752 case mfMAGICFIRE:
2753 if(!hints)
2754 {
2755 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2756 }
2757 else
2758 {
2759 tempitem=getItemID(itemsbuf,itype_wand,1);
2760
2761 if(tempitem<0) break;
2762
2763 tempweapon=wFire;
2764
2765 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2766 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2767 {
2768 tempitemx=x;
2769 tempitemy=y;
2770 }
2771 else
2772 {
2773 tempweaponx=x;
2774 tempweapony=y;
2775 }
2776
2777 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2778 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2779 }
2780
2781 break;
2782
2783 case mfDIVINEFIRE:
2784 if(!hints)
2785 {
2786 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2787 }
2788 else
2789 {
2790 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2791
2792 if(tempitem<0) break;
2793
2794 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2795 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2796 {
2797 tempitemx=x;
2798 tempitemy=y;
2799 }
2800
2801 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2802 }
2803
2804 break;
2805
2806 case mfARROW:
2807
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2808 {
2809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
2810 732 }
2811 else
2812 {
2813 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2814
2815
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2816
2817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2818
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2819 {
2820 61 tempitemx=x;
2821 61 tempitemy=y;
2822 61 }
2823
2824 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2825 }
2826
2827 814 break;
2828
2829 case mfSARROW:
2830 if(!hints)
2831 {
2832 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
2833 }
2834 else
2835 {
2836 tempitem=getItemID(itemsbuf,itype_arrow,2);
2837
2838 if(tempitem<0) break;
2839
2840 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2841 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2842 {
2843 tempitemx=x;
2844 tempitemy=y;
2845 }
2846
2847 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2848 }
2849
2850 break;
2851
2852 case mfGARROW:
2853 if(!hints)
2854 {
2855 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
2856 }
2857 else
2858 {
2859 tempitem=getItemID(itemsbuf,itype_arrow,3);
2860
2861 if(tempitem<0) break;
2862
2863 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2864 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2865 {
2866 tempitemx=x;
2867 tempitemy=y;
2868 }
2869
2870 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2871 }
2872
2873 break;
2874
2875 case mfBOMB:
2876
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2877 {
2878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
2879 76 }
2880 else
2881 {
2882 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2883 17 tempweapon = wLitBomb;
2884
2885 //if (tempitem<0) break;
2886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2887
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2888 {
2889 12 tempweaponx=x;
2890 12 tempweapony=y;
2891 12 }
2892
2893 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2894 }
2895
2896 93 break;
2897
2898 case mfSBOMB:
2899
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2900 {
2901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
2902 48 }
2903 else
2904 {
2905 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2906 //if (tempitem<0) break;
2907 48 tempweapon = wLitSBomb;
2908
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2910
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2911 {
2912 36 tempweaponx=x;
2913 36 tempweapony=y;
2914 36 }
2915
2916 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2917 }
2918
2919 96 break;
2920
2921 case mfARMOS_SECRET:
2922
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2923 {
2924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
2925 12 }
2926 24 break;
2927
2928 case mfBRANG:
2929
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2930 {
2931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
2932 20 }
2933 else
2934 {
2935 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2936
2937
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2938
2939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2940
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2941 {
2942 4 tempitemx=x;
2943 4 tempitemy=y;
2944 4 }
2945
2946 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2947 }
2948
2949 25 break;
2950
2951 case mfMBRANG:
2952 if(!hints)
2953 {
2954 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
2955 }
2956 else
2957 {
2958 tempitem=getItemID(itemsbuf,itype_brang,2);
2959
2960 if(tempitem<0) break;
2961
2962 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2963 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2964 {
2965 tempitemx=x;
2966 tempitemy=y;
2967 }
2968
2969 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2970 }
2971
2972 break;
2973
2974 case mfFBRANG:
2975 if(!hints)
2976 {
2977 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
2978 }
2979 else
2980 {
2981 tempitem=getItemID(itemsbuf,itype_brang,3);
2982
2983 if(tempitem<0) break;
2984
2985 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2986 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2987 {
2988 tempitemx=x;
2989 tempitemy=y;
2990 }
2991
2992 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2993 }
2994
2995 break;
2996
2997 case mfWANDMAGIC:
2998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2999 {
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3001 138 }
3002 else
3003 {
3004 tempitem=getItemID(itemsbuf,itype_wand,1);
3005
3006 if(tempitem<0) break;
3007
3008 tempweapon=itemsbuf[tempitem].wpn3;
3009
3010 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3011 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3012 {
3013 tempitemx=x;
3014 tempitemy=y;
3015 }
3016 else
3017 {
3018 tempweaponx=x;
3019 tempweapony=y;
3020 --lens_hint_weapon[wMagic][4];
3021
3022 if(lens_hint_weapon[wMagic][4]<-8)
3023 {
3024 lens_hint_weapon[wMagic][4]=8;
3025 }
3026 }
3027
3028 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3029 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3030 }
3031
3032 138 break;
3033
3034 case mfREFMAGIC:
3035
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3036 {
3037 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3038 }
3039 else
3040 {
3041 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3042
3043
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3044
3045 16 tempweapon=ewMagic;
3046
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3048
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3049 {
3050 13 tempitemx=x;
3051 13 tempitemy=y;
3052 13 }
3053 else
3054 {
3055 3 tempweaponx=x;
3056 3 tempweapony=y;
3057
3058
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3059 {
3060 1 --lens_hint_weapon[ewMagic][4];
3061 1 }
3062 else
3063 {
3064 2 ++lens_hint_weapon[ewMagic][4];
3065 }
3066
3067
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3068 {
3069 lens_hint_weapon[ewMagic][2]=up;
3070 }
3071
3072
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3073 {
3074 2 lens_hint_weapon[ewMagic][2]=down;
3075 2 }
3076 }
3077
3078 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3079 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3080 }
3081
3082 16 break;
3083
3084 case mfREFFIREBALL:
3085
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3086 {
3087 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3088 }
3089 else
3090 {
3091 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3092
3093
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3094
3095 16 tempweapon=ewFireball;
3096
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3098
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3099 {
3100 12 tempitemx=x;
3101 12 tempitemy=y;
3102 12 tempweaponx=x;
3103 12 tempweapony=y;
3104 12 ++lens_hint_weapon[ewFireball][3];
3105
3106
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3107 {
3108 1 lens_hint_weapon[ewFireball][3]=-8;
3109 1 lens_hint_weapon[ewFireball][4]=8;
3110 1 }
3111
3112
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3113 {
3114 8 ++lens_hint_weapon[ewFireball][4];
3115 8 }
3116 else
3117 {
3118 4 --lens_hint_weapon[ewFireball][4];
3119 }
3120 12 }
3121
3122 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3123 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3124 }
3125
3126 16 break;
3127
3128 case mfSWORD:
3129
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3130 {
3131 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3132 }
3133 else
3134 {
3135 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3136
3137
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3138
3139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3140
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3141 {
3142 5 tempitemx=x;
3143 5 tempitemy=y;
3144 5 }
3145
3146 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3147 }
3148
3149 7 break;
3150
3151 case mfWSWORD:
3152 if(!hints)
3153 {
3154 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3155 }
3156 else
3157 {
3158 tempitem=getItemID(itemsbuf,itype_sword,2);
3159
3160 if(tempitem<0) break;
3161
3162 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3163 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3164 {
3165 tempitemx=x;
3166 tempitemy=y;
3167 }
3168
3169 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3170 }
3171
3172 break;
3173
3174 case mfMSWORD:
3175 if(!hints)
3176 {
3177 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3178 }
3179 else
3180 {
3181 tempitem=getItemID(itemsbuf,itype_sword,3);
3182
3183 if(tempitem<0) break;
3184
3185 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3186 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3187 {
3188 tempitemx=x;
3189 tempitemy=y;
3190 }
3191
3192 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3193 }
3194
3195 break;
3196
3197 case mfXSWORD:
3198 if(!hints)
3199 {
3200 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3201 }
3202 else
3203 {
3204 tempitem=getItemID(itemsbuf,itype_sword,4);
3205
3206 if(tempitem<0) break;
3207
3208 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3209 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3210 {
3211 tempitemx=x;
3212 tempitemy=y;
3213 }
3214
3215 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3216 }
3217
3218 break;
3219
3220 case mfSWORDBEAM:
3221
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3222 {
3223 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3224 }
3225 else
3226 {
3227 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3228
3229
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3230
3231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3232
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3233 {
3234 11 tempitemx=x;
3235 11 tempitemy=y;
3236 11 }
3237
3238 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3239 }
3240
3241 16 break;
3242
3243 case mfWSWORDBEAM:
3244 if(!hints)
3245 {
3246 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3247 }
3248 else
3249 {
3250 tempitem=getItemID(itemsbuf,itype_sword,2);
3251
3252 if(tempitem<0) break;
3253
3254 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3255 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3256 {
3257 tempitemx=x;
3258 tempitemy=y;
3259 }
3260
3261 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3262 }
3263
3264 break;
3265
3266 case mfMSWORDBEAM:
3267 if(!hints)
3268 {
3269 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3270 }
3271 else
3272 {
3273 tempitem=getItemID(itemsbuf,itype_sword,3);
3274
3275 if(tempitem<0) break;
3276
3277 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3278 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3279 {
3280 tempitemx=x;
3281 tempitemy=y;
3282 }
3283
3284 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3285 }
3286
3287 break;
3288
3289 case mfXSWORDBEAM:
3290 if(!hints)
3291 {
3292 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3293 }
3294 else
3295 {
3296 tempitem=getItemID(itemsbuf,itype_sword,4);
3297
3298 if(tempitem<0) break;
3299
3300 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3301 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3302 {
3303 tempitemx=x;
3304 tempitemy=y;
3305 }
3306
3307 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3308 }
3309
3310 break;
3311
3312 case mfHOOKSHOT:
3313
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3314 {
3315 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3316 }
3317 else
3318 {
3319 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3320
3321
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3322
3323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3324
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3325 {
3326 12 tempitemx=x;
3327 12 tempitemy=y;
3328 12 }
3329
3330 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3331 }
3332
3333 17 break;
3334
3335 case mfWAND:
3336
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3337 {
3338 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3339 }
3340 else
3341 {
3342 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3343
3344
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3345
3346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3347
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3348 {
3349 28 tempitemx=x;
3350 28 tempitemy=y;
3351 28 }
3352
3353 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3354 }
3355
3356 35 break;
3357
3358 case mfHAMMER:
3359
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3360 {
3361 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3362 }
3363 else
3364 {
3365 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3366
3367
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3368
3369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3370
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3371 {
3372 13 tempitemx=x;
3373 13 tempitemy=y;
3374 13 }
3375
3376 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3377 }
3378
3379 17 break;
3380
3381 case mfARMOS_ITEM:
3382 case mfDIVE_ITEM:
3383
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✓ Branch 2 taken 2602 times.
✗ Branch 3 not taken.
2602 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3384 {
3385 2602 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3386 2602 }
3387 2602 break;
3388
3389 case 16:
3390 case 17:
3391 case 18:
3392 case 19:
3393 case 20:
3394 case 21:
3395 case 22:
3396 case 23:
3397 case 24:
3398 case 25:
3399 case 26:
3400 case 27:
3401 case 28:
3402 case 29:
3403 case 30:
3404 case 31:
3405
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3407 107890 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3408
3409 108898 break;
3410 case mfSECRETSNEXT:
3411 if(!hints)
3412 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3413 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3414
3415 break;
3416
3417 case mfSTRIKE:
3418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3419 {
3420 906 goto special;
3421 }
3422 else
3423 {
3424 break;
3425 }
3426
3427 28750 default: goto special;
3428
3429 special:
3430
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3431 {
3432
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3433 {
3434 4954 rectfill(dest,x,y,x+15,y+15,WHITE);
3435 4954 }
3436 6604 }
3437
3438 29656 break;
3439 }
3440 7043520 }
3441 3521760 }
3442
3443
2/2
✓ Branch 0 taken 10005 times.
✓ Branch 1 taken 10005 times.
20010 if(layer)
3444 {
3445
2/2
✓ Branch 0 taken 9646 times.
✓ Branch 1 taken 359 times.
10005 if(tmpscr->door[0]==dWALK)
3446 359 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3447
3448
2/2
✓ Branch 0 taken 9582 times.
✓ Branch 1 taken 423 times.
10005 if(tmpscr->door[1]==dWALK)
3449 423 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3450
3451
2/2
✓ Branch 0 taken 9423 times.
✓ Branch 1 taken 582 times.
10005 if(tmpscr->door[2]==dWALK)
3452 582 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3453
3454
2/2
✓ Branch 0 taken 9381 times.
✓ Branch 1 taken 624 times.
10005 if(tmpscr->door[3]==dWALK)
3455 624 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3456
3457
2/2
✓ Branch 0 taken 9962 times.
✓ Branch 1 taken 43 times.
10005 if(tmpscr->door[0]==dBOMB)
3458 {
3459 43 showbombeddoor(dest, 0);
3460 43 }
3461
3462
2/2
✓ Branch 0 taken 9966 times.
✓ Branch 1 taken 39 times.
10005 if(tmpscr->door[1]==dBOMB)
3463 {
3464 39 showbombeddoor(dest, 1);
3465 39 }
3466
3467
2/2
✓ Branch 0 taken 9999 times.
✓ Branch 1 taken 6 times.
10005 if(tmpscr->door[2]==dBOMB)
3468 {
3469 6 showbombeddoor(dest, 2);
3470 6 }
3471
3472
2/2
✓ Branch 0 taken 9968 times.
✓ Branch 1 taken 37 times.
10005 if(tmpscr->door[3]==dBOMB)
3473 {
3474 37 showbombeddoor(dest, 3);
3475 37 }
3476 10005 }
3477
3478
2/2
✓ Branch 0 taken 17976 times.
✓ Branch 1 taken 2034 times.
20010 if(tmpscr->stairx + tmpscr->stairy)
3479 {
3480
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3481 {
3482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3483 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3484 1123 }
3485 else
3486 {
3487
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3488 {
3489 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3490 48 int32_t tempitemx=-16;
3491 48 int32_t tempitemy=-16;
3492
3493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3494
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3495 {
3496 24 tempitemx=tmpscr->stairx;
3497 24 tempitemy=tmpscr->stairy+playing_field_offset;
3498 24 }
3499
3500 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3501 48 }
3502 }
3503 2034 }
3504 }
3505 20010 }
3506
3507 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3508
3509 9666 void draw_lens_over()
3510 {
3511 // Oh, what the heck.
3512 static BITMAP *lens_scr = NULL;
3513 static int32_t last_width = -1;
3514 9666 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3515
3516 // Only redraw the circle if the size has changed
3517
2/2
✓ Branch 0 taken 9647 times.
✓ Branch 1 taken 19 times.
9666 if(width != last_width)
3518 {
3519
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2 times.
19 if(lens_scr == NULL)
3520 {
3521 17 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3522 17 }
3523
3524 19 clear_to_color(lens_scr, BLACK);
3525 19 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3526 19 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3527 19 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3528 19 last_width=width;
3529 19 }
3530
3531 9666 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3532 9666 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3533 9666 }
3534
3535 //----------------------------------------------------------------
3536
3537 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3538 {
3539 //recreating a big bitmap every frame is highly sluggish.
3540
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3541 31797 clear_to_color(wavebuf, BLACK);
3542 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3543
3544 int32_t ofs;
3545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3546
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3547 31797 int32_t amp2=168;
3548
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3549 31797 int32_t i=frame%amp2;
3550
3551
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<168; j++)
3552 {
3553
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3554 {
3555 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3556 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3557 }
3558 else
3559 {
3560 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3561 }
3562
3563
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3564 {
3565
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3566 {
3567 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3568 1367525376 }
3569 5341896 }
3570 5341896 }
3571 31797 }
3572
3573 28224 void draw_fuzzy(int32_t fuzz)
3574 // draws from right half of scrollbuf to framebuf
3575 {
3576 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3577 byte *start, *si, *di;
3578
3579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28224 times.
28224 if(fuzz<1)
3580 fuzz = 1;
3581
3582 28224 xstep = 128%fuzz;
3583
3584
2/2
✓ Branch 0 taken 5880 times.
✓ Branch 1 taken 22344 times.
28224 if(xstep > 0)
3585 22344 xstep = fuzz-xstep;
3586
3587 28224 ystep = 112%fuzz;
3588
3589
2/2
✓ Branch 0 taken 8232 times.
✓ Branch 1 taken 19992 times.
28224 if(ystep > 0)
3590 19992 ystep = fuzz-ystep;
3591
3592 28224 firsty = 1;
3593
3594
2/2
✓ Branch 0 taken 28224 times.
✓ Branch 1 taken 1018416 times.
1046640 for(y=0; y<224;)
3595 {
3596 1018416 start = &(scrollbuf->line[y][256]);
3597
3598
4/4
✓ Branch 0 taken 1004304 times.
✓ Branch 1 taken 6336288 times.
✓ Branch 2 taken 6322176 times.
✓ Branch 3 taken 1018416 times.
7340592 for(dy=0; dy<ystep && dy+y<224; dy++)
3599 {
3600 6322176 si = start;
3601 6322176 di = &(framebuf->line[y+dy][0]);
3602 6322176 i = xstep;
3603 6322176 firstx = 1;
3604
3605
2/2
✓ Branch 0 taken 1618477056 times.
✓ Branch 1 taken 6322176 times.
1624799232 for(dx=0; dx<256; dx++)
3606 {
3607 1618477056 *(di++) = *si;
3608
3609
2/2
✓ Branch 0 taken 1363746048 times.
✓ Branch 1 taken 254731008 times.
1618477056 if(++i >= fuzz)
3610 {
3611
2/2
✓ Branch 0 taken 248408832 times.
✓ Branch 1 taken 6322176 times.
254731008 if(!firstx)
3612 248408832 si += fuzz;
3613 else
3614 {
3615 6322176 si += fuzz-xstep;
3616 6322176 firstx = 0;
3617 }
3618
3619 254731008 i = 0;
3620 254731008 }
3621 1618477056 }
3622 6322176 }
3623
3624
2/2
✓ Branch 0 taken 990192 times.
✓ Branch 1 taken 28224 times.
1018416 if(!firsty)
3625 990192 y += fuzz;
3626 else
3627 {
3628 28224 y += ystep;
3629 28224 ystep = fuzz;
3630 28224 firsty = 0;
3631 }
3632 }
3633 28224 }
3634
3635 18306906 void updatescr(bool allowwavy)
3636 {
3637
4/6
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 18306647 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 259 times.
✓ Branch 4 taken 259 times.
✗ Branch 5 not taken.
18306906 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3638
4/6
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 18306647 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 259 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259 times.
18306906 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3639
3640
2/2
✓ Branch 0 taken 18279601 times.
✓ Branch 1 taken 27305 times.
18306906 if(toogam)
3641 {
3642 27305 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3643 27305 }
3644
3645
1/2
✓ Branch 0 taken 18306906 times.
✗ Branch 1 not taken.
18306906 if(Showpal)
3646 dump_pal(framebuf);
3647
3648
2/2
✓ Branch 0 taken 17793882 times.
✓ Branch 1 taken 513024 times.
18306906 if(!Playing)
3649 513024 black_opening_count=0;
3650
3651
2/2
✓ Branch 0 taken 18143277 times.
✓ Branch 1 taken 163629 times.
18306906 if(black_opening_count<0) //shape is opening up
3652 {
3653 163629 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3654
3655
2/4
✓ Branch 0 taken 163629 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 163629 times.
163629 if(Advance||(!Paused))
3656 {
3657 163629 ++black_opening_count;
3658 163629 }
3659 163629 }
3660
2/2
✓ Branch 0 taken 18095295 times.
✓ Branch 1 taken 47982 times.
18143277 else if(black_opening_count>0) //shape is closing
3661 {
3662 47982 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3663
3664
2/4
✓ Branch 0 taken 47982 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 47982 times.
47982 if(Advance||(!Paused))
3665 {
3666 47982 --black_opening_count;
3667 47982 }
3668 47982 }
3669
3670
3/4
✓ Branch 0 taken 18098501 times.
✓ Branch 1 taken 208405 times.
✓ Branch 2 taken 18098501 times.
✗ Branch 3 not taken.
18306906 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3671 {
3672 black_opening_shape = bosCIRCLE;
3673 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3674 refreshTints();
3675 refreshpal=true;
3676 }
3677
3678
2/2
✓ Branch 0 taken 17678147 times.
✓ Branch 1 taken 628759 times.
18306906 if(refreshpal)
3679 {
3680 628759 refreshpal=false;
3681 628759 RAMpal[253] = _RGB(0,0,0);
3682 628759 RAMpal[254] = _RGB(255,255,255);
3683 628759 hw_palette = &RAMpal;
3684 628759 update_hw_pal = true;
3685
3686 // Creating rgb_table and trans_table is pretty expensive, so try not to redo the same work
3687 // within a short period of time by using a cache.
3688 typedef std::array<uint32_t, PAL_SIZE> pal_table_cache_key;
3689 struct pal_table_cache_entry {
3690 RGB_MAP rgb_table;
3691 COLOR_MAP trans_table;
3692 };
3693
3/4
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 628500 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 259 times.
628759 static std::map<pal_table_cache_key, pal_table_cache_entry> pal_table_cache;
3694
3695 static constexpr int pal_table_cache_max_memory_mb = 10;
3696 static constexpr int pal_table_cache_max_size = pal_table_cache_max_memory_mb / ((double)sizeof(pal_table_cache_entry) / 1024 / 1024);
3697
2/2
✓ Branch 0 taken 628594 times.
✓ Branch 1 taken 165 times.
628759 if (pal_table_cache.size() > pal_table_cache_max_size)
3698 165 pal_table_cache.clear();
3699
3700 pal_table_cache_key key;
3701
2/2
✓ Branch 0 taken 160962304 times.
✓ Branch 1 taken 628759 times.
161591063 for (int i = 0; i < PAL_SIZE; i++)
3702 160962304 key[i] = RAMpal[i].r + (RAMpal[i].g << 8) + (RAMpal[i].b << 16);
3703 628759 auto cache_it = pal_table_cache.find(key);
3704
2/2
✓ Branch 0 taken 24966 times.
✓ Branch 1 taken 603793 times.
628759 if (cache_it == pal_table_cache.end())
3705 {
3706 24966 create_rgb_table(&rgb_table, RAMpal, NULL);
3707 24966 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3708 24966 pal_table_cache[key] = {rgb_table, trans_table};
3709 24966 trans_table2 = trans_table;
3710 24966 }
3711 else
3712 {
3713 603793 rgb_table = cache_it->second.rgb_table;
3714 603793 trans_table = cache_it->second.trans_table;
3715 603793 trans_table2 = cache_it->second.trans_table;
3716 }
3717
3718
2/2
✓ Branch 0 taken 160962304 times.
✓ Branch 1 taken 628759 times.
161591063 for(int32_t q=0; q<PAL_SIZE; q++)
3719 {
3720 160962304 trans_table2.data[0][q] = q;
3721 160962304 trans_table2.data[q][q] = q;
3722 160962304 }
3723 628759 }
3724
3725 18306906 bool clearwavy = (wavy <= 0);
3726
3727
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18298565 times.
18306906 if(wavy <= 0)
3728 {
3729 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3730 18298565 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3731 18298565 }
3732
3733 18306906 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3734
3735
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18274859 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18306906 if(wavy && Playing && allowwavy)
3736 {
3737 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3738 31797 }
3739
3740
2/2
✓ Branch 0 taken 18298565 times.
✓ Branch 1 taken 8341 times.
18306906 if(clearwavy)
3741 18298565 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3742
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3743 8341 wavy--; // Wavy was set by a script. Decrement it.
3744
3745
5/6
✓ Branch 0 taken 17793882 times.
✓ Branch 1 taken 513024 times.
✓ Branch 2 taken 664395 times.
✓ Branch 3 taken 17129487 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 664395 times.
18306906 if(Playing && msgpos && !screenscrolling)
3746 {
3747
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_bg_display_buf->clip))
3748 664395 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3749
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_portrait_display_buf->clip))
3750 664395 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3751
1/2
✓ Branch 0 taken 664395 times.
✗ Branch 1 not taken.
664395 if(!(msg_txt_display_buf->clip))
3752 664395 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3753 664395 }
3754
3755
2/2
✓ Branch 0 taken 18120397 times.
✓ Branch 1 taken 186509 times.
18306906 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3756
3757
2/2
✓ Branch 0 taken 18125670 times.
✓ Branch 1 taken 181236 times.
18306906 if(nosubscr)
3758 {
3759 181236 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3760 181236 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3761 181236 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3762 181236 }
3763
3764 //TODO: Optimize blit 'overcalls' -Gleeok
3765
2/2
✓ Branch 0 taken 181236 times.
✓ Branch 1 taken 18125670 times.
18306906 BITMAP *source = nosubscr ? panorama : wavybuf;
3766 18306906 blit(source,framebuf,0,0,0,0,256,224);
3767
3768 18306906 update_hw_screen();
3769 18306906 }
3770
3771 //----------------------------------------------------------------
3772
3773 static PALETTE syspal;
3774 int32_t onGUISnapshot()
3775 {
3776 char buf[200];
3777 int32_t num=0;
3778 do
3779 {
3780 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3781 }
3782 while(num<99999 && exists(buf));
3783
3784 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3785 InfoDialog("Error", "Failed to save snapshot").show();
3786
3787 return D_O_K;
3788 }
3789
3790 int32_t onNonGUISnapshot()
3791 {
3792 PALETTE temppal;
3793 get_palette(temppal);
3794 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3795
3796 char buf[200];
3797 int32_t num=0;
3798
3799 do
3800 {
3801 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3802 }
3803 while(num<99999 && exists(buf));
3804
3805 if ((tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET)) && !(key[KEY_ALT]))
3806 {
3807 BITMAP *b = create_bitmap_ex(8,256,168);
3808 clear_to_color(b,0);
3809 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3810 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3811 destroy_bitmap(b);
3812 }
3813 else
3814 {
3815 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3816 }
3817
3818 return D_O_K;
3819 }
3820
3821 int32_t onSnapshot()
3822 {
3823 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3824 {
3825 onGUISnapshot();
3826 }
3827 else
3828 {
3829 onNonGUISnapshot();
3830 }
3831
3832 return D_O_K;
3833 }
3834
3835 int32_t onSaveMapPic()
3836 {
3837 int32_t mapres2 = 0;
3838 char buf[200];
3839 int32_t num=0;
3840 mapscr tmpscr_b[2];
3841 mapscr tmpscr_c[6];
3842 BITMAP* _screen_draw_buffer = NULL;
3843 _screen_draw_buffer = create_bitmap_ex(8,256,224);
3844 set_clip_state(_screen_draw_buffer,1);
3845
3846 for(int32_t i=0; i<6; ++i)
3847 {
3848 tmpscr_c[i] = tmpscr2[i];
3849 tmpscr2[i].zero_memory();
3850
3851 if(i>=2)
3852 {
3853 continue;
3854 }
3855
3856 tmpscr_b[i] = tmpscr[i];
3857 tmpscr[i].zero_memory();
3858 }
3859
3860 do
3861 {
3862 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3863 }
3864 while(num<99999 && exists(buf));
3865
3866 BITMAP* mappic = NULL;
3867
3868
3869 bool done=false, redraw=true;
3870
3871 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
3872
3873 if(!mappic)
3874 {
3875 enter_sys_pal();
3876 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3877 exit_sys_pal();
3878 return D_O_K;;
3879 }
3880
3881 // draw the map
3882 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
3883
3884 for(int32_t y=0; y<8; y++)
3885 {
3886 for(int32_t x=0; x<16; x++)
3887 {
3888 if(!displayOnMap(x, y))
3889 {
3890 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
3891 }
3892 else
3893 {
3894 int32_t s = (y<<4) + x;
3895 loadscr2(1,s,-1);
3896
3897 for(int32_t i=0; i<6; i++)
3898 {
3899 if(tmpscr[1].layermap[i]<=0)
3900 continue;
3901
3902 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
3903 }
3904
3905 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3906
3907 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3908
3909 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
3910 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
3911
3912 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3913
3914 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
3915 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3916 {
3917 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
3918 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3919 {
3920 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
3921 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
3922 }
3923 }
3924 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
3925
3926 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3927
3928 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
3929 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
3930 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3931 {
3932 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
3933 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
3934 }
3935 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
3936 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
3937
3938 }
3939
3940 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
3941 }
3942 }
3943
3944 for(int32_t i=0; i<6; ++i)
3945 {
3946 tmpscr2[i]=tmpscr_c[i];
3947
3948 if(i>=2)
3949 {
3950 continue;
3951 }
3952
3953 tmpscr[i]=tmpscr_b[i];
3954 }
3955
3956 save_bitmap(buf,mappic,RAMpal);
3957 destroy_bitmap(mappic);
3958 destroy_bitmap(_screen_draw_buffer);
3959 return D_O_K;
3960 }
3961
3962 55 void f_Quit(int32_t type)
3963 {
3964
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 if(type==qQUIT && !Playing)
3965 return;
3966
3967 55 bool from_menu = is_sys_pal;
3968
3969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
3970 {
3971 55 music_pause();
3972 55 pause_all_sfx();
3973 55 sys_mouse();
3974 55 }
3975 55 enter_sys_pal();
3976 55 clear_keybuf();
3977
3978
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 13 times.
55 if (replay_version_check(0, 10))
3979 13 replay_poll();
3980
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (replay_is_replaying())
3981 55 replay_peek_quit();
3982
3983
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (!replay_is_replaying())
3984 switch(type)
3985 {
3986 case qQUIT:
3987 onQuit();
3988 break;
3989
3990 case qRESET:
3991 onReset();
3992 break;
3993
3994 case qEXIT:
3995 onExit();
3996 break;
3997 }
3998
3999
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(Quit)
4000 {
4001 55 kill_sfx();
4002 55 music_stop();
4003 55 exit_sys_pal();
4004 55 update_hw_screen();
4005 55 }
4006 else
4007 {
4008 exit_sys_pal();
4009 if(!from_menu)
4010 {
4011 music_resume();
4012 resume_all_sfx();
4013 }
4014 }
4015
4016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
4017 55 game_mouse();
4018 55 eat_buttons();
4019
4020 55 zc_readrawkey(KEY_ESC);
4021
4022 55 zc_readrawkey(KEY_ENTER);
4023 55 }
4024
4025 //----------------------------------------------------------------
4026
4027 int32_t onNoWalls()
4028 {
4029 cheats_enqueue(Cheat::Walls);
4030 return D_O_K;
4031 }
4032
4033 int32_t onIgnoreSideview()
4034 {
4035 cheats_enqueue(Cheat::IgnoreSideView);
4036 return D_O_K;
4037 }
4038
4039 18305549 int32_t input_idle(bool checkmouse)
4040 {
4041 static int32_t mx, my, mz, mb;
4042
4043
4/6
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4902281 times.
✓ Branch 3 taken 13403268 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4902281 times.
23207830 if(keypressed() || zc_key_pressed() ||
4044
4/8
✓ Branch 0 taken 4902281 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4902281 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4902281 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4902281 times.
✗ Branch 7 not taken.
4902281 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4045 {
4046 13403268 idle_count = 0;
4047
4048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13403268 times.
13403268 if(active_count < MAX_ACTIVE)
4049 {
4050 13403268 ++active_count;
4051 13403268 }
4052 13403268 }
4053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4902281 times.
4902281 else if(idle_count < MAX_IDLE)
4054 {
4055 4902281 ++idle_count;
4056 4902281 active_count = 0;
4057 4902281 }
4058
4059 18305549 mx = mouse_x;
4060 18305549 my = mouse_y;
4061 18305549 mz = mouse_z;
4062 18305549 mb = mouse_b;
4063
4064 18305549 return idle_count;
4065 }
4066
4067 int32_t onGoFast()
4068 {
4069 cheats_enqueue(Cheat::Fast);
4070 return D_O_K;
4071 }
4072
4073 int32_t onKillCheat()
4074 {
4075 cheats_enqueue(Cheat::Kill);
4076 return D_O_K;
4077 }
4078
4079 int32_t onSecretsCheat()
4080 {
4081 cheats_enqueue(Cheat::TrigSecrets);
4082 return D_O_K;
4083 }
4084 int32_t onSecretsCheatPerm()
4085 {
4086 cheats_enqueue(Cheat::TrigSecretsPerm);
4087 return D_O_K;
4088 }
4089
4090 int32_t onShowLayer0()
4091 {
4092 show_layer_0 = !show_layer_0;
4093 return D_O_K;
4094 }
4095 int32_t onShowLayer1()
4096 {
4097 show_layer_1 = !show_layer_1;
4098 return D_O_K;
4099 }
4100 int32_t onShowLayer2()
4101 {
4102 show_layer_2 = !show_layer_2;
4103 return D_O_K;
4104 }
4105 int32_t onShowLayer3()
4106 {
4107 show_layer_3 = !show_layer_3;
4108 return D_O_K;
4109 }
4110 int32_t onShowLayer4()
4111 {
4112 show_layer_4 = !show_layer_4;
4113 return D_O_K;
4114 }
4115 int32_t onShowLayer5()
4116 {
4117 show_layer_5 = !show_layer_5;
4118 return D_O_K;
4119 }
4120 int32_t onShowLayer6()
4121 {
4122 show_layer_6 = !show_layer_6;
4123 return D_O_K;
4124 }
4125 int32_t onShowLayerO()
4126 {
4127 show_layer_over=!show_layer_over;
4128 return D_O_K;
4129 }
4130 int32_t onShowLayerP()
4131 {
4132 show_layer_push=!show_layer_push;
4133 return D_O_K;
4134 }
4135 int32_t onShowLayerS()
4136 {
4137 show_sprites=!show_sprites;
4138 return D_O_K;
4139 }
4140 int32_t onShowLayerF()
4141 {
4142 show_ffcs=!show_ffcs;
4143 return D_O_K;
4144 }
4145 int32_t onShowLayerW()
4146 {
4147 show_walkflags=!show_walkflags;
4148 if(show_walkflags)
4149 show_effectflags = false;
4150 return D_O_K;
4151 }
4152 int32_t onShowLayerE()
4153 {
4154 show_effectflags=!show_effectflags;
4155 if(show_effectflags)
4156 show_walkflags = false;
4157 return D_O_K;
4158 }
4159 int32_t onShowFFScripts()
4160 {
4161 show_ff_scripts=!show_ff_scripts;
4162 return D_O_K;
4163 }
4164 int32_t onShowHitboxes()
4165 {
4166 show_hitboxes=!show_hitboxes;
4167 return D_O_K;
4168 }
4169 int32_t onShowInfoOpacity()
4170 {
4171 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4172 zc_set_config("zc","debug_info_opacity",info_opacity);
4173 return D_O_K;
4174 }
4175
4176 int32_t onLightSwitch()
4177 {
4178 cheats_enqueue(Cheat::Light);
4179 return D_O_K;
4180 }
4181
4182 int32_t onGoTo();
4183 int32_t onGoToComplete();
4184
4185 18305549 bool handle_close_btn_quit()
4186 {
4187
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(close_button_quit)
4188 {
4189 close_button_quit=false;
4190 f_Quit(qEXIT);
4191 }
4192 18305549 return (exiting_program = Quit==qEXIT);
4193 }
4194
4195 18305549 void syskeys()
4196 {
4197 18305549 update_system_keys();
4198
4199 int32_t oldtitle_version;
4200
4201 18305549 poll_joystick();
4202
4203 18305549 handle_close_btn_quit();
4204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
18305549 if(Quit == qEXIT) return;
4205
4206
2/10
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18305549 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18305549 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4207 {
4208 System();
4209 }
4210
4211 18305549 mouse_down=gui_mouse_b();
4212
4213
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(zc_read_system_key(KEY_F1))
4214 {
4215 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4216 {
4217 halt=!halt;
4218 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4219 }
4220 else
4221 {
4222 Throttlefps=!Throttlefps;
4223 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4224 }
4225 }
4226
4227
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(zc_read_system_key(KEY_F2))
4228 {
4229 ShowFPS=!ShowFPS;
4230 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4231 }
4232
4233
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18305549 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4234
4235
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18305549 if(zc_read_system_key(KEY_F4) && Playing)
4236 {
4237 Paused=true;
4238 Advance=true;
4239 }
4240
4241
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(zc_read_system_key(KEY_F6)) onTryQuit();
4242
4243 #ifndef ALLEGRO_MACOSX
4244
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4245
4246
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4247 #else
4248 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4249
4250 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4251 #endif
4252
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18305549 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4253
4254
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if (zc_read_system_key(KEY_F12))
4255 {
4256 onSnapshot();
4257 }
4258
4259
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18305549 if(debug_enabled && zc_read_system_key(KEY_TAB))
4260 set_debug(!get_debug());
4261
4262
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(CheatModifierKeys())
4263 {
4264 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4265 {
4266 if(!bindable_cheat(c))
4267 continue;
4268 if(get_debug() || cheat >= cheat_lvl(c))
4269 {
4270 if(checkcheat(c))
4271 cheats_hit_bind(c);
4272 }
4273 }
4274 }
4275
4276
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(volkeys)
4277 {
4278 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4279
4280 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4281
4282 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4283
4284 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4285 }
4286
4287
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18305549 if(!get_debug() || !SystemKeys || replay_is_replaying())
4288 18305549 goto bottom;
4289
4290 if(zc_readkey(KEY_P)) Paused=!Paused;
4291
4292 if(zc_readkey(KEY_A))
4293 {
4294 Paused=true;
4295 Advance=true;
4296 }
4297
4298 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4299 #ifndef ALLEGRO_MACOSX
4300 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4301
4302 if(zc_readkey(KEY_F7))
4303 {
4304 Matrix(ss_speed, ss_density, 0);
4305 game_pal();
4306 }
4307 #else
4308 // The reason these are different on Mac in the first place is that
4309 // the OS doesn't let us use F9 and F10...
4310 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4311
4312 if(zc_readkey(KEY_F9))
4313 {
4314 Matrix(ss_speed, ss_density, 0);
4315 game_pal();
4316 }
4317 #endif
4318 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4319 {
4320 //change containers
4321 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4322 {
4323 //magic containers
4324 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4325 {
4326 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4327 }
4328 else
4329 {
4330 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4331 }
4332 }
4333 else
4334 {
4335 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4336 {
4337 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4338 }
4339 else
4340 {
4341 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4342 }
4343 }
4344 }
4345
4346 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4347 {
4348 //change containers
4349 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4350 {
4351 //magic containers
4352 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4353 {
4354 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4355 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4356 //heart containers
4357 }
4358 else
4359 {
4360 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4361 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4362 }
4363 }
4364 else
4365 {
4366 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4367 {
4368 game->set_magic(zc_max(game->get_magic()-1,0));
4369 }
4370 else
4371 {
4372 game->set_life(zc_max(game->get_life()-1,0));
4373 }
4374 }
4375 }
4376
4377 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4378
4379 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4380
4381 verifyBothWeapons();
4382
4383 bottom:
4384
4385
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(input_idle(true) > after_time())
4386 {
4387 Matrix(ss_speed, ss_density, 0);
4388 game_pal();
4389 }
4390 18305549 }
4391
4392 1115304 void checkQuitKeys()
4393 {
4394 #ifndef ALLEGRO_MACOSX
4395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1115304 times.
1115304 if(key[KEY_F9]) f_Quit(qRESET);
4396
4397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1115304 times.
1115304 if(key[KEY_F10]) f_Quit(qEXIT);
4398 #else
4399 if(key[KEY_F7]) f_Quit(qRESET);
4400
4401 if(key[KEY_F8]) f_Quit(qEXIT);
4402 #endif
4403 1115304 }
4404
4405 18305749 bool CheatModifierKeys()
4406 {
4407 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4408 // to trigger cheats.
4409
2/2
✓ Branch 0 taken 18305449 times.
✓ Branch 1 taken 300 times.
18305749 if (replay_is_replaying())
4410 18305449 return false;
4411
4412
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4413
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4415 {
4416
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4417 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4418 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4419 {
4420 return true;
4421 }
4422 }
4423 100 return false;
4424 18305549 }
4425
4426 //99:05:54, for some reason?
4427 #define OLDMAXTIME 21405240
4428 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4429 #define MAXTIME 1944000000
4430
4431 18306906 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4432 {
4433
1/2
✓ Branch 0 taken 18306906 times.
✗ Branch 1 not taken.
18306906 if(zcmusic!=NULL)
4434 {
4435 zcmusic_poll();
4436 }
4437 18306906 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4438
4439 18306906 updatescr(allowwavy);
4440
4441 18306906 Advance=false;
4442
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18306906 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18306906 times.
18306906 while(Paused && !Advance && !Quit)
4443 {
4444 // have to call this, otherwise we'll get an infinite loop
4445 syskeys();
4446 if(allowF6Script)
4447 {
4448 FFCore.runF6Engine();
4449 }
4450
4451 #ifdef _WIN32
4452
4453 if(use_dwm_flush)
4454 {
4455 do_DwmFlush();
4456 }
4457
4458 #endif
4459
4460 // to keep music playing
4461 if(zcmusic!=NULL)
4462 {
4463 zcmusic_poll();
4464 }
4465
4466 update_hw_screen();
4467 }
4468
4469
2/2
✓ Branch 0 taken 18305584 times.
✓ Branch 1 taken 1322 times.
18306906 if(Quit)
4470 1322 return;
4471
4472
3/4
✓ Branch 0 taken 17792862 times.
✓ Branch 1 taken 512722 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17792862 times.
18305584 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4473 17792862 game->change_time(1);
4474
4475 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4476
4477 18305584 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4478
2/2
✓ Branch 0 taken 8595970 times.
✓ Branch 1 taken 9709614 times.
18305584 if (replay_version_check(0, 16))
4479 9709614 should_reset_down_state = replay_version_check(11, 16);
4480
2/2
✓ Branch 0 taken 14979009 times.
✓ Branch 1 taken 3326575 times.
18305584 if (should_reset_down_state)
4481 {
4482
2/2
✓ Branch 0 taken 59878350 times.
✓ Branch 1 taken 3326575 times.
63204925 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4483 59878350 down_control_states[i] = raw_control_state[i];
4484 3326575 }
4485
4486
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 18305549 times.
18305584 if (replay_is_active())
4487 {
4488
2/2
✓ Branch 0 taken 1545422 times.
✓ Branch 1 taken 16760127 times.
18305549 if (replay_version_check(3))
4489 16760127 replay_poll();
4490
4491
4/4
✓ Branch 0 taken 7388911 times.
✓ Branch 1 taken 10916638 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7288376 times.
18305549 if (replay_version_check(11) || replay_version_check(6, 8))
4492 11017173 replay_peek_input();
4493 18305549 }
4494
4495 18305584 load_control_called_this_frame = false;
4496
4497 18305584 poll_keyboard();
4498 18305584 update_keys();
4499
4500 18305584 ++frame;
4501
4502
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 18305449 times.
18305584 if (replay_is_replaying())
4503 18305449 replay_do_cheats();
4504 18305584 syskeys();
4505
4506 // The mouse variables can change from the mouse thread at anytime during a frame,
4507 // so save the result at the start so that replaying is consistent.
4508 18305584 script_mouse_x = gui_mouse_x();
4509 18305584 script_mouse_y = gui_mouse_y();
4510 18305584 script_mouse_z = mouse_z;
4511 18305584 script_mouse_b = mouse_b;
4512
4513 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4514 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4515 // approach here means it doesn't matter which call adds the cheat.
4516 18305584 cheats_execute_queued();
4517
4518
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 18305449 times.
18305584 if (replay_is_replaying())
4519 18305449 replay_peek_quit();
4520
2/2
✓ Branch 0 taken 18305529 times.
✓ Branch 1 taken 55 times.
18305584 if (GameFlags & GAMEFLAG_TRYQUIT)
4521 55 replay_step_quit(0);
4522
2/2
✓ Branch 0 taken 3320 times.
✓ Branch 1 taken 18302264 times.
18305584 if(allowF6Script)
4523 18302264 FFCore.runF6Engine();
4524
2/2
✓ Branch 0 taken 712 times.
✓ Branch 1 taken 18304872 times.
18305584 if (Quit)
4525 712 replay_step_quit(Quit);
4526
4527 #ifdef _WIN32
4528
4529 if(use_dwm_flush)
4530 {
4531 do_DwmFlush();
4532 }
4533
4534 #endif
4535
4536
2/2
✓ Branch 0 taken 208643 times.
✓ Branch 1 taken 18096941 times.
18305584 if(sfxcleanup)
4537 18096941 sfx_cleanup();
4538
4539 18305584 jit_poll();
4540
4541 #ifdef __EMSCRIPTEN__
4542 // Yield the main thread back to the browser occasionally.
4543 if (is_headless())
4544 {
4545 static int rate = 10000;
4546 static int force_yield = rate;
4547 if (force_yield++ >= rate)
4548 {
4549 force_yield = 0;
4550 emscripten_sleep(0);
4551 }
4552 }
4553 #endif
4554
4555
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18305484 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18305584 if (zqtesting_mode && test_mode_auto_restart)
4556 {
4557 static auto last_write_time = fs::last_write_time(qstpath);
4558 static auto last_check = std::chrono::system_clock::now();
4559
4560 if (std::chrono::system_clock::now() - last_check > 200ms)
4561 {
4562 last_check = std::chrono::system_clock::now();
4563 auto write_time = fs::last_write_time(qstpath);
4564 if (last_write_time != write_time)
4565 {
4566 last_write_time = write_time;
4567 disableClickToFreeze = false;
4568 Quit = qRESET;
4569 replay_quit();
4570 }
4571 }
4572 }
4573 18306906 }
4574
4575 589 void zapout()
4576 {
4577 589 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4578 589 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4579
4580 589 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4581 589 script_drawing_commands.Clear();
4582
4583 // zap out
4584
2/2
✓ Branch 0 taken 589 times.
✓ Branch 1 taken 14136 times.
14725 for(int32_t i=1; i<=24; i++)
4585 {
4586 14136 draw_fuzzy(i);
4587 14136 advanceframe(true);
4588
4589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14136 times.
14136 if(Quit)
4590 {
4591 break;
4592 }
4593 14136 }
4594 589 }
4595
4596 587 void zapin()
4597 {
4598 587 FFCore.warpScriptCheck();
4599 587 draw_screen(tmpscr);
4600 587 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4601 587 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4602
4603 // zap out
4604 587 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4605
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 14088 times.
14675 for(int32_t i=24; i>=1; i--)
4606 {
4607 14088 draw_fuzzy(i);
4608 14088 advanceframe(true);
4609
4610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14088 times.
14088 if(Quit)
4611 {
4612 break;
4613 }
4614 14088 }
4615 587 }
4616
4617
4618 235 void wavyout(bool showhero)
4619 {
4620 235 draw_screen(tmpscr, showhero);
4621
4622 235 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4623 235 clear_to_color(wavebuf,0);
4624 235 blit(framebuf,wavebuf,0,0,16,0,256,224);
4625
4626 static PALETTE wavepal;
4627
4628 int32_t ofs;
4629 235 int32_t amplitude=8;
4630
4631 235 int32_t wavelength=4;
4632 235 double palpos=0, palstep=4, palstop=126;
4633
4634 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4635
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<168; i+=wavelength)
4636 {
4637
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4638 {
4639 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4640 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4641 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4642 2520320 }
4643
4644 9845 palpos+=palstep;
4645
4646
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4647 {
4648 9845 hw_palette = &wavepal;
4649 9845 update_hw_pal = true;
4650 9845 }
4651 else
4652 {
4653 hw_palette = &RAMpal;
4654 update_hw_pal = true;
4655 }
4656
4657
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<224; j++)
4658 {
4659
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4660 {
4661 423413760 ofs=0;
4662
4663
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4664 {
4665 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4666 103224320 }
4667
4668 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4669 423413760 }
4670 1653960 }
4671
4672 9845 advanceframe(true);
4673
4674
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4675 1 break;
4676 9844 }
4677
4678 235 destroy_bitmap(wavebuf);
4679
4680 235 hw_palette = &RAMpal;
4681 235 update_hw_pal = true;
4682 235 }
4683
4684 232 void wavyin()
4685 {
4686 232 draw_screen(tmpscr);
4687
4688 232 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4689 232 clear_to_color(wavebuf,0);
4690 232 blit(framebuf,wavebuf,0,0,16,0,256,224);
4691
4692 static PALETTE wavepal;
4693
4694 232 refreshpal=false;
4695 int32_t ofs;
4696 232 int32_t amplitude=8;
4697 232 int32_t wavelength=4;
4698 232 double palpos=168, palstep=4, palstop=126;
4699
4700 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4701
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<168; i+=wavelength)
4702 {
4703
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4704 {
4705 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4706 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4707 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4708 2483968 }
4709
4710 9703 palpos-=palstep;
4711
4712
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4713 {
4714 9703 hw_palette = &wavepal;
4715 9703 update_hw_pal = true;
4716 9703 }
4717 else
4718 {
4719 hw_palette = &RAMpal;
4720 update_hw_pal = true;
4721 }
4722
4723
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<224; j++)
4724 {
4725
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4726 {
4727 417306624 ofs=0;
4728
4729
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(167-i))&&(j&1))
4730 {
4731 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4732 104337152 }
4733
4734 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4735 417306624 }
4736 1630104 }
4737
4738 9703 advanceframe(true);
4739
4740
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4741 1 break;
4742 9702 }
4743
4744 232 destroy_bitmap(wavebuf);
4745
4746 232 hw_palette = &RAMpal;
4747 232 update_hw_pal = true;
4748 232 }
4749
4750 4332 void blackscr(int32_t fcnt,bool showsubscr)
4751 {
4752 4332 reset_pal_cycling();
4753 4332 script_drawing_commands.Clear();
4754
4755 4332 FFCore.warpScriptCheck();
4756 4332 bool showtime = game->should_show_time();
4757
2/2
✓ Branch 0 taken 4325 times.
✓ Branch 1 taken 129517 times.
133842 while(fcnt>0)
4758 {
4759 129517 clear_bitmap(framebuf);
4760
4761
2/2
✓ Branch 0 taken 59250 times.
✓ Branch 1 taken 70267 times.
129517 if(showsubscr)
4762 {
4763 70267 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4764
3/4
✓ Branch 0 taken 70267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1230 times.
✓ Branch 3 taken 69037 times.
70267 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4765 {
4766 1230 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4767 1230 }
4768 70267 }
4769
4770 129517 advanceframe(true);
4771
4772
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129510 times.
129517 if(Quit)
4773 7 break;
4774
4775 129510 --fcnt;
4776 }
4777 4332 }
4778
4779 2656 void openscreen(int32_t shape)
4780 {
4781 2656 reset_pal_cycling();
4782 2656 black_opening_count=0;
4783
4784
3/4
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 2134 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 522 times.
2656 if(COOLSCROLL || shape>-1)
4785 {
4786 2134 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4787 2134 return;
4788 }
4789 else
4790 {
4791 522 Hero.setDontDraw(true);
4792 522 show_subscreen_dmap_dots=false;
4793 522 show_subscreen_numbers=false;
4794 522 show_subscreen_life=false;
4795 }
4796
4797 522 int32_t x=128;
4798
4799 522 FFCore.warpScriptCheck();
4800
2/2
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 41760 times.
42282 for(int32_t i=0; i<80; i++)
4801 {
4802 41760 draw_screen(tmpscr);
4803 41760 x=128-(((i*128/80)/8)*8);
4804
4805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(x>0)
4806 {
4807 41760 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4808 41760 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4809 41760 }
4810
4811 41760 advanceframe(true);
4812
4813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(Quit)
4814 {
4815 break;
4816 }
4817 41760 }
4818
4819 522 Hero.setDontDraw(false);
4820 522 show_subscreen_items=true;
4821 522 show_subscreen_dmap_dots=true;
4822 522 show_subscreen_numbers=true;
4823 522 show_subscreen_life=true;
4824 2656 }
4825
4826 4 void closescreen(int32_t shape)
4827 {
4828 4 reset_pal_cycling();
4829 4 black_opening_count=0;
4830
4831
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if(COOLSCROLL || shape>-1)
4832 {
4833 4 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4834 4 return;
4835 }
4836 else
4837 {
4838 Hero.setDontDraw(true);
4839 show_subscreen_dmap_dots=false;
4840 show_subscreen_numbers=false;
4841 // show_subscreen_items=false;
4842 show_subscreen_life=false;
4843 }
4844
4845 int32_t x=128;
4846
4847 FFCore.warpScriptCheck();
4848 for(int32_t i=79; i>=0; --i)
4849 {
4850 draw_screen(tmpscr);
4851 x=128-(((i*128/80)/8)*8);
4852
4853 if(x>0)
4854 {
4855 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4856 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4857 }
4858
4859 advanceframe(true);
4860
4861 if(Quit)
4862 {
4863 break;
4864 }
4865 }
4866
4867 Hero.setDontDraw(false);
4868 show_subscreen_items=true;
4869 show_subscreen_dmap_dots=true;
4870 4 }
4871
4872 296 int32_t TriforceCount()
4873 {
4874 296 int32_t c=0;
4875
4876
2/2
✓ Branch 0 taken 2368 times.
✓ Branch 1 taken 296 times.
2664 for(int32_t i=1; i<=8; i++)
4877
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 1884 times.
4252 if(game->lvlitems[i]&liTRIFORCE)
4878 1884 ++c;
4879
4880 296 return c;
4881 }
4882
4883 int32_t onCustomGame()
4884 {
4885 auto save = get_unset_save_slot();
4886 if (!save)
4887 return D_CLOSE;
4888
4889 if (prompt_for_quest_path(save->header->qstpath))
4890 {
4891 save->header->qstpath = qstpath;
4892 return D_O_K;
4893 }
4894
4895 return D_CLOSE;
4896 }
4897
4898 int32_t onContinue()
4899 {
4900 return D_CLOSE;
4901 }
4902
4903 int32_t onThrottleFPS()
4904 {
4905 Throttlefps = !Throttlefps;
4906 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4907 return D_O_K;
4908 }
4909
4910 int32_t onWinPosSave()
4911 {
4912 SaveWinPos = !SaveWinPos;
4913 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4914 return D_O_K;
4915 }
4916 int32_t onIntegerScaling()
4917 {
4918 scaleForceInteger = !scaleForceInteger;
4919 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4920 return D_O_K;
4921 }
4922 int32_t onStretchGame()
4923 {
4924 stretchGame = !stretchGame;
4925 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4926 return D_O_K;
4927 }
4928
4929 int32_t onClickToFreeze()
4930 {
4931 ClickToFreeze = !ClickToFreeze;
4932 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4933 return D_O_K;
4934 }
4935
4936 int32_t OnSaveZCConfig()
4937 {
4938 if(jwin_alert3(
4939 "Save Configuration",
4940 "Are you sure that you wish to save your present configuration settings?",
4941 "This will overwrite your prior settings!",
4942 NULL,
4943 "&Yes",
4944 "&No",
4945 NULL,
4946 'y',
4947 'n',
4948 0,
4949 get_zc_font(font_lfont)) == 1)
4950 {
4951 save_game_configs();
4952 return D_O_K;
4953 }
4954 else return D_O_K;
4955 }
4956
4957 int32_t OnnClearQuestDir()
4958 {
4959 auto current_path = fs::current_path() / "quests";
4960 if(jwin_alert3(
4961 "Clear Current Directory Cache",
4962 "Are you sure that you wish to reset where ZC Player looks for quests?",
4963 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4964 NULL,
4965 "&Yes",
4966 "&No",
4967 NULL,
4968 'y',
4969 'n',
4970 0,
4971 get_zc_font(font_lfont)) == 1)
4972 {
4973 zc_set_config("zeldadx","quest_dir","quests");
4974 flush_config_file();
4975 strcpy(qstdir,"quests");
4976 #ifdef __EMSCRIPTEN__
4977 em_sync_fs();
4978 #endif
4979 return D_O_K;
4980 }
4981 else return D_O_K;
4982 }
4983
4984 int32_t onConsole()
4985 {
4986 if ( !console_enabled )
4987 {
4988 AlertDialog("ZC Console",
4989 "Open the ZC Console?"
4990 "\nThis will display any messages logged by scripts,"
4991 " including errors.",
4992 [&](bool ret,bool)
4993 {
4994 if(ret)
4995 {
4996 FFCore.ZScriptConsole(true);
4997 }
4998 }).show();
4999 return D_O_K;
5000 }
5001 else
5002 {
5003 FFCore.ZScriptConsole(false);
5004 return D_O_K;
5005 }
5006 }
5007
5008 int32_t onClrConsoleOnReload()
5009 {
5010 clearConsoleOnReload = !clearConsoleOnReload;
5011 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5012 return D_O_K;
5013 }
5014 int32_t onClrConsoleOnLoad()
5015 {
5016 clearConsoleOnLoad = !clearConsoleOnLoad;
5017 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5018 return D_O_K;
5019 }
5020
5021
5022 int32_t onFrameSkip()
5023 {
5024 FrameSkip = !FrameSkip;
5025 return D_O_K;
5026 }
5027
5028 int32_t onSaveDragResize()
5029 {
5030 SaveDragResize = !SaveDragResize;
5031 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5032 return D_O_K;
5033 }
5034
5035 int32_t onDragAspect()
5036 {
5037 DragAspect = !DragAspect;
5038 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5039 return D_O_K;
5040 }
5041
5042 int32_t onTransLayers()
5043 {
5044 TransLayers = !TransLayers;
5045 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5046 return D_O_K;
5047 }
5048
5049 int32_t onNESquit()
5050 {
5051 NESquit = !NESquit;
5052 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5053 return D_O_K;
5054 }
5055
5056 int32_t onVolKeys()
5057 {
5058 volkeys = !volkeys;
5059 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5060 return D_O_K;
5061 }
5062
5063 int32_t onShowFPS()
5064 {
5065 ShowFPS = !ShowFPS;
5066 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5067 return D_O_K;
5068 }
5069
5070 int32_t onShowTime()
5071 {
5072 ShowGameTime = !ShowGameTime;
5073 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5074 return D_O_K;
5075 }
5076
5077 2160054782 bool is_Fkey(int32_t k)
5078 {
5079
2/2
✓ Branch 0 taken 219666588 times.
✓ Branch 1 taken 1940388194 times.
2160054782 switch(k)
5080 {
5081 case KEY_F1:
5082 case KEY_F2:
5083 case KEY_F3:
5084 case KEY_F4:
5085 case KEY_F5:
5086 case KEY_F6:
5087 case KEY_F7:
5088 case KEY_F8:
5089 case KEY_F9:
5090 case KEY_F10:
5091 case KEY_F11:
5092 case KEY_F12:
5093 219666588 return true;
5094 }
5095
5096 1940388194 return false;
5097 2160054782 }
5098
5099 void kb_getkey(DIALOG *d);
5100
5101 //Used by all keyboard key settings dialogues.
5102 void kb_clearjoystick(DIALOG *d)
5103 {
5104 d->flags|=D_SELECTED;
5105
5106 jwin_button_proc(MSG_DRAW,d,0);
5107 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5108 // text_mode(vc(11));
5109 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5110 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5111
5112 update_hw_screen();
5113
5114 clear_keybuf();
5115 int32_t k = next_press_key();
5116 clear_keybuf();
5117
5118 //shnarf
5119 //47=f1
5120 //59=esc
5121 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5122 // *((int32_t*)d->dp3) = k;
5123 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5124
5125
5126 d->flags&=~D_SELECTED;
5127 }
5128
5129 //Clears key to 0.
5130 //Used by all keyboard key settings dialogues.
5131 void kb_clearkey(DIALOG *d);
5132
5133 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5134 {
5135 switch(msg)
5136 {
5137 case MSG_KEY:
5138 case MSG_CLICK:
5139
5140 kb_clearjoystick(d);
5141
5142 while(gui_mouse_b())
5143 {
5144 clear_keybuf();
5145 rest(1);
5146 }
5147
5148 return D_REDRAW;
5149 }
5150
5151 return jwin_button_proc(msg,d,c);
5152 }
5153
5154 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5155 //Only used in keyboard settings dialogues to clear keys.
5156 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5157
5158 int32_t j_getbtn(DIALOG *d)
5159 {
5160 d->flags|=D_SELECTED;
5161 jwin_button_proc(MSG_DRAW,d,0);
5162 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5163 // text_mode(vc(11));
5164 int32_t y = screen->h/2 - 12;
5165 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5166 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5167 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5168
5169 update_hw_screen();
5170
5171 int32_t b = next_joy_input(true);
5172 if (b == -2)
5173 return D_CLOSE;
5174
5175 if(b>=0)
5176 *((int32_t*)d->dp3) = b;
5177
5178 d->flags&=~D_SELECTED;
5179
5180 return D_O_K;
5181 }
5182
5183 void j_getstick(DIALOG *d)
5184 {
5185 d->flags|=D_SELECTED;
5186 jwin_button_proc(MSG_DRAW,d,0);
5187 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5188 // text_mode(vc(11));
5189 int32_t y = screen->h/2 - 12;
5190 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5191 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5192 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5193
5194 update_hw_screen();
5195
5196 int32_t b = next_joy_input(false);
5197
5198 if(b>=0)
5199 *((int32_t*)d->dp3) = b;
5200
5201 d->flags&=~D_SELECTED;
5202 }
5203
5204 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5205 {
5206 switch(msg)
5207 {
5208 case MSG_KEY:
5209 case MSG_CLICK:
5210
5211 int ret = j_getbtn(d);
5212 if (ret != D_O_K)
5213 return ret;
5214
5215 while(gui_mouse_b()) {
5216 rest(1);
5217 clear_keybuf();
5218 }
5219
5220 return D_REDRAW;
5221 }
5222
5223 return jwin_button_proc(msg,d,c);
5224 }
5225
5226 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5227 {
5228 switch(msg)
5229 {
5230 case MSG_KEY:
5231 case MSG_CLICK:
5232
5233 j_getstick(d);
5234
5235 while(gui_mouse_b()) {
5236 rest(1);
5237 clear_keybuf();
5238 }
5239
5240 return D_REDRAW;
5241 }
5242
5243 return jwin_button_proc(msg,d,c);
5244 }
5245
5246 //shnarf
5247 extern const char *key_str[];
5248 std::string get_keystr(int key);
5249
5250 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5251
5252 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5253 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5254 str_primary_stick[80], str_secondary_stick[80];
5255
5256 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5257 {
5258 //these are here to bypass compiler warnings about unused arguments
5259 c=c;
5260
5261 if (d->w == 1)
5262 {
5263 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5264 {
5265 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5266 return D_CLOSE;
5267 }
5268 }
5269
5270 if(msg==MSG_DRAW)
5271 {
5272 switch(d->w)
5273 {
5274 case 0:
5275 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5276 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5277 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5278 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5279 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5280 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5281 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5282 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5283 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5284 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5285 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5286 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5287 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5288 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5289 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5290 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5291 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5292 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5293 break;
5294
5295 case 1:
5296 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5297 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5298 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5299 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5300 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5301 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5302 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5303 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5304 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5305 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5306 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5307 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5308 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5309 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5310 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5311 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5312 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5313 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5314 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5315 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5316 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5317 break;
5318
5319 case 2:
5320 sprintf(str_a," %3d",midi_volume);
5321 sprintf(str_l," %3d",emusic_volume);
5322 sprintf(str_r," %3d",sfx_volume);
5323 strcpy(str_s,pan_str[pan_style]);
5324 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5325 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5326 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5327 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5328 break;
5329 }
5330 }
5331
5332 return D_O_K;
5333 }
5334
5335 int32_t set_vol(void *dp3, int32_t d2)
5336 {
5337 switch(((int32_t*)dp3)[0])
5338 {
5339 case 0:
5340 midi_volume = zc_min(d2<<3,255);
5341 break;
5342
5343 case 1:
5344 digi_volume = zc_min(d2<<3,255);
5345 break;
5346
5347 case 2:
5348 emusic_volume = zc_min(d2<<3,255);
5349 break;
5350
5351 case 3:
5352 sfx_volume = zc_min(d2<<3,255);
5353 break;
5354 }
5355
5356 // text_mode(vc(11));
5357 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5358 return D_O_K;
5359 }
5360
5361 int32_t set_pan(void *dp3, int32_t d2)
5362 {
5363 pan_style = vbound(d2,0,3);
5364 // text_mode(vc(11));
5365 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5366 return D_O_K;
5367 }
5368
5369 static int32_t gamepad_joys_list[] =
5370 {
5371 61,
5372 -1
5373 };
5374
5375 static int32_t gamepad_btn_list[] =
5376 {
5377 6,
5378 7,8,9,10,11,12,13,14,15,16,17,
5379 18,19,20,21,22,23,24,25,26,27,28,
5380 29,30,31,32,33,34,35,36,37,38,39,
5381 -1
5382 };
5383
5384 static int32_t gamepad_dirs_list[] =
5385 {
5386 40,41,42,43,
5387 44,45,46,47,
5388 48,49,50,51,
5389 52,53,54,55,
5390 56,57,58,59,
5391 60,
5392 -1
5393 };
5394
5395 static TABPANEL gamepad_tabs[] =
5396 {
5397 // (text)
5398 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5399 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5400 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5401 { NULL, 0, NULL, 0, NULL }
5402 };
5403
5404 const char *joy_list(int32_t index, int32_t *list_size)
5405 {
5406 if (index == -1)
5407 {
5408 *list_size = al_get_num_joysticks();
5409 return NULL;
5410 }
5411
5412 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5413 if (!joy)
5414 {
5415 return "?";
5416 }
5417
5418 return al_get_joystick_name(joy);
5419 }
5420
5421 349 static ListData joy__list(joy_list, &font);
5422
5423 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5424 {
5425 int32_t d2 = d->d2;
5426 int32_t ret = jwin_droplist_proc(msg,d,c);
5427
5428 if(d2!=d->d2)
5429 {
5430 joystick_index = d->d2;
5431 ret |= D_REDRAW_ALL;
5432 }
5433
5434 return ret;
5435 }
5436
5437 static DIALOG gamepad_dlg[] =
5438 {
5439 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5440 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5441 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5442 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5443 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5444 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5445 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5446 // 6
5447 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5448 // 7
5449 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5450 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5451 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5452 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5453 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5454 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5455 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5456 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5457 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5458 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5459 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5460 // 18
5461 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5462 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5463 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5464 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5465 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5466 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5467 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5468 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5469 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5470 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5471 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5472 // 29
5473 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5474 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5475 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5476 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5477 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5478 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5479 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5480 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5481 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5482 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5483 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5484 // 40
5485 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5486 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5487 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5488 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5489 // 44
5490 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5491 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5492 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5493 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5494 // 48
5495 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5496 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5497 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5498 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5499 // 52
5500 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5501 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5502 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5503 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5504 // 56
5505 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5506 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5507 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5508 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5509 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5510
5511 // 61
5512 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5513
5514 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5515 };
5516
5517 static int32_t keyboard_keys_list[] =
5518 {
5519 6,7,8,9,10,
5520 11,12,13,14,15,16,17,18,19,20,
5521 21,22,23,24,25,26,27,28,29,30,
5522 31,32,33,34,35,36,37,38,39,40,
5523 -1
5524 };
5525
5526 static int32_t keyboard_dirs_list[] =
5527 {
5528 41,42,43,44,
5529 45,46,47,48,
5530 49,50,51,52,
5531 53,54,55,56,
5532 -1
5533 };
5534
5535 static int32_t keyboard_mods_list[] =
5536 {
5537 57,58,59,60,
5538 61,62,63,64,
5539 65,66,67,68,
5540 69,70,71,72,
5541 -1
5542 };
5543
5544 static TABPANEL keyboard_control_tabs[] =
5545 {
5546 // (text)
5547 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5548 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5549 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5550 { NULL, 0, NULL, 0, NULL }
5551 };
5552
5553 static DIALOG keyboard_control_dlg[] =
5554 {
5555 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5556 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5557 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5558 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5559 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5560 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5561 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5562 // Keys
5563 // 6
5564 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5565 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5566 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5567 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5568 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5569 // 11
5570 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5571 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5572 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5573 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5574 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5575 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5576 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5577 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5578 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5579 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5580 // 21
5581 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5582 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5583 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5584 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5585 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5586 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5587 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5588 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5589 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5590 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5591 // 31
5592 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5593 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5594 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5595 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5596 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5597 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5598 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5599 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5600 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5601 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5602 // Dirs
5603 // 41
5604 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5605 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5606 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5607 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5608 // 45
5609 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5610 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5611 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5612 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5613 // 49
5614 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5615 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5616 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5617 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5618 // 53
5619 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5620 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5621 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5622 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5623 // Mods
5624 // 57
5625 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5626 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5627 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5628 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5629 // 61
5630 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5631 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5632 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5633 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5634 // 65
5635 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5636 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5637 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5638 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5639 // 69
5640 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5641 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5642 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5643 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5644 // 73
5645 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5646 };
5647
5648 int32_t midi_dp[3] = {0,0,0};
5649 int32_t emus_dp[3] = {2,0,0};
5650 int32_t sfx_dp[3] = {3,0,0};
5651 int32_t pan_dp[3] = {0,0,0};
5652
5653 static DIALOG sound_dlg[] =
5654 {
5655 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5656 349 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5657 349 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5658 349 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5659 349 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5660 349 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5661 349 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5662 349 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5663 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5664 349 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5665 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5666 // 10
5667 349 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5668 349 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5669 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5670 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5671 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5672 349 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5673 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5674 349 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5675 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5676 349 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5677 //20
5678 349 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5679 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5681 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5682 349 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5683 349 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5684 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 349 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5686 349 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5687 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 //30
5689 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5690 349 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5691 349 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5692 };
5693
5694 char zc_builddate[80];
5695 char zc_aboutstr[80];
5696
5697 static DIALOG about_dlg[] =
5698 {
5699 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5700 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5701 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5702 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5703 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5704 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5705 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5706 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5707 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5708 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5709 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5710 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5711 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5712 };
5713
5714
5715 static DIALOG quest_dlg[] =
5716 {
5717 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5718 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5719 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5720 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5721 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5722 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5723 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5724 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5725 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5726 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5727 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5728 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5729 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5730 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5731 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5732 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5733 };
5734
5735 static DIALOG triforce_dlg[] =
5736 {
5737 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5738 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5739 // 1
5740 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5741 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5742 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5743 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5744 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5745 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5746 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5747 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5748 // 9
5749 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5750 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5751 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5752 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5753 };
5754
5755 int32_t onToggleRecordingNewSaves()
5756 {
5757 if (zc_get_config("zeldadx", "replay_new_saves", false))
5758 {
5759 zc_set_config("zeldadx", "replay_new_saves", false);
5760 }
5761 else
5762 {
5763 zc_set_config("zeldadx", "replay_new_saves", true);
5764 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5765 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5766 }
5767 return D_O_K;
5768 }
5769
5770 #ifdef HAS_CURL
5771 int32_t onToggleAutoUploadReplays()
5772 {
5773 if (zc_get_config("zeldadx", "replay_upload", false))
5774 {
5775 zc_set_config("zeldadx", "replay_upload", false);
5776 }
5777 else
5778 {
5779 zc_set_config("zeldadx", "replay_upload", true);
5780 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5781 " preventing bugs and simplifying bug reports.",
5782 "Upload will happen no more than once a week when closing ZC",
5783 "OK",NULL,13,27,get_zc_font(font_lfont));
5784
5785 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5786 onToggleRecordingNewSaves();
5787 }
5788 return D_O_K;
5789 }
5790
5791 int32_t onUploadReplays()
5792 {
5793 if(jwin_alert3(
5794 "Upload replays",
5795 "Upload your replays now to assist in development?",
5796 NULL,
5797 NULL,
5798 "&Yes",
5799 "&No",
5800 NULL,
5801 'y',
5802 'n',
5803 0,
5804 get_zc_font(font_lfont)) == 1)
5805 {
5806 int num_uploaded = replay_upload();
5807 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5808 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5809 }
5810 return D_O_K;
5811 }
5812
5813 int32_t onClearUploadCache()
5814 {
5815 if(jwin_alert3(
5816 "Upload replays",
5817 "Clear the upload cache?",
5818 "This simply deletes replays/state.json. There's no harm in doing this, but",
5819 "likely is not necessary.",
5820 "&Yes",
5821 "&No",
5822 NULL,
5823 'y',
5824 'n',
5825 0,
5826 get_zc_font(font_lfont)) == 1)
5827 {
5828 replay_upload_clear_cache();
5829 }
5830 return D_O_K;
5831 }
5832 #endif
5833
5834 int32_t onToggleSnapshotAllFrames()
5835 {
5836 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5837 return D_O_K;
5838 }
5839
5840 int32_t onStopReplayOrRecord()
5841 {
5842 if (replay_is_replaying())
5843 {
5844 replay_quit();
5845 }
5846 else if (replay_get_mode() == ReplayMode::Record)
5847 {
5848 if (!replay_get_meta_bool("test_mode"))
5849 {
5850 jwin_alert("Recording", "You cannot stop recording a save file.",
5851 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5852 return D_CLOSE;
5853 }
5854
5855 if (jwin_alert("Stop Recording",
5856 "Save replay to disk and stop recording?",
5857 "This will stop the recording.",
5858 NULL,
5859 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5860 return D_CLOSE;
5861
5862 replay_save();
5863 replay_stop();
5864 }
5865 return D_O_K;
5866 }
5867
5868 static int32_t handle_on_load_replay(ReplayMode mode)
5869 {
5870 bool ctrl = CHECK_CTRL_CMD;
5871 if (Playing)
5872 {
5873 if (jwin_alert("Replay - Warning!",
5874 "Loading a replay will exit the current game.",
5875 "All unsaved progress will be lost.",
5876 "Do you wish to continue?",
5877 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5878 return D_CLOSE;
5879 }
5880
5881 std::string mode_string = replay_mode_to_string(mode);
5882 mode_string[0] = std::toupper(mode_string[0]);
5883
5884 std::string line_1 = "Select a replay file to play back.";
5885 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5886 std::string line_3 = "You can stop the replay and take over manually any time.";
5887 if (mode == ReplayMode::Update)
5888 {
5889 line_1 = "Select a replay file to update.";
5890 line_2 = "WARNING: be sure to back up the zplay file";
5891 line_3 = "and verify that the updated replay works as expected!";
5892 }
5893
5894 if (jwin_alert(mode_string.c_str(),
5895 line_1.c_str(),
5896 line_2.c_str(),
5897 line_3.c_str(),
5898 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5899 {
5900 std::string replay_path = "replays/";
5901 if(ctrl && devpwd())
5902 replay_path = "../../tests/replays/";
5903 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5904 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5905 replay_path = *result;
5906 else
5907 return D_CLOSE;
5908
5909 replay_quit();
5910 load_replay_file_deferred(mode, replay_path);
5911 Quit = qRESET;
5912 return D_CLOSE;
5913 }
5914 return D_O_K;
5915 }
5916
5917 int32_t onLoadReplay()
5918 {
5919 return handle_on_load_replay(ReplayMode::Replay);
5920 }
5921
5922 int32_t onLoadReplayAssert()
5923 {
5924 return handle_on_load_replay(ReplayMode::Assert);
5925 }
5926
5927 int32_t onLoadReplayUpdate()
5928 {
5929 return handle_on_load_replay(ReplayMode::Update);
5930 }
5931
5932 int32_t onSaveReplay()
5933 {
5934 if (replay_get_mode() == ReplayMode::Record)
5935 {
5936 if (!replay_get_meta_bool("test_mode"))
5937 {
5938 if (jwin_alert("Save Replay",
5939 "This will save a copy of the replay up to this point.",
5940 "The official replay file will be untouched.",
5941 "Do you wish to continue?",
5942 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5943 {
5944 return D_CLOSE;
5945 }
5946
5947 std::string replay_path = replay_get_replay_path().string();
5948 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5949 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5950 replay_path = *result;
5951 else
5952 return D_CLOSE;
5953
5954 if (fileexists(replay_path.c_str()))
5955 {
5956 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5957 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5958 return D_CLOSE;
5959 }
5960
5961 replay_save(replay_path);
5962 }
5963 else
5964 {
5965 replay_save();
5966 }
5967 }
5968 return D_O_K;
5969 }
5970
5971 enum
5972 {
5973 MENUID_REPLAY_RECORDNEW,
5974 MENUID_REPLAY_STOP,
5975 MENUID_REPLAY_SAVE,
5976 MENUID_REPLAY_SNAP_ALL,
5977 MENUID_REPLAY_AUTOUPLOAD,
5978 MENUID_REPLAY_UPLOAD,
5979 MENUID_REPLAY_CLEARUPLOADCACHE,
5980 };
5981
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu replay_menu
5982 4537 {
5983
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5984
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
5985
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
5986
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Load replay", onLoadReplay },
5987
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Load replay (assert)", onLoadReplayAssert },
5988
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Load replay (update)", onLoadReplayUpdate },
5989
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
5990
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
5991 #ifdef HAS_CURL
5992
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
5993
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
5994
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
5995
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
5996 #endif
5997 };
5998
5999 static DIALOG credits_dlg[] =
6000 {
6001 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6002 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6003 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6004 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6005 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6006 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6007 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6008 };
6009
6010 349 static ListData dmap_list(dmaplist, &font);
6011
6012 static DIALOG goto_dlg[] =
6013 {
6014 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6015 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6016 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6017 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6018 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6019 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6020 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6021 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6022 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6023 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6024 };
6025
6026 int32_t onGoTo()
6027 {
6028 bool music = false;
6029 music = music;
6030 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6031
6032 goto_dlg[0].dp2=get_zc_font(font_lfont);
6033 goto_dlg[4].d2=cheat_goto_dmap;
6034 goto_dlg[6].dp=cheat_goto_screen_str;
6035
6036 clear_keybuf();
6037
6038 large_dialog(goto_dlg);
6039
6040 if(do_zqdialog(goto_dlg,4)==1)
6041 {
6042 int dmap = goto_dlg[4].d2;
6043 int screen = zc_xtoi(cheat_goto_screen_str);
6044 int adjusted_screen = screen + DMaps[dmap].xoff;
6045 if (adjusted_screen < 0 || adjusted_screen >= 128)
6046 {
6047 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6048 }
6049 else
6050 {
6051 cheats_enqueue(Cheat::GoTo, dmap, screen);
6052 }
6053 };
6054
6055 return D_O_K;
6056 }
6057
6058 int32_t onGoToComplete()
6059 {
6060 if(!Playing)
6061 {
6062 return D_O_K;
6063 }
6064
6065 enter_sys_pal();
6066 music_pause();
6067 pause_all_sfx();
6068 onGoTo();
6069 eat_buttons();
6070
6071 zc_readrawkey(KEY_ESC);
6072
6073 exit_sys_pal();
6074 music_resume();
6075 resume_all_sfx();
6076 return D_O_K;
6077 }
6078
6079 int32_t onCredits()
6080 {
6081 return D_O_K;
6082 }
6083
6084 const char *midilist(int32_t index, int32_t *list_size)
6085 {
6086 if(index<0)
6087 {
6088 *list_size=0;
6089
6090 for(int32_t i=0; i<MAXMIDIS; i++)
6091 if(tunes[i].data)
6092 ++(*list_size);
6093
6094 return NULL;
6095 }
6096
6097 int32_t i=0,m=0;
6098
6099 while(m<=index && i<=MAXMIDIS)
6100 {
6101 if(tunes[i].data)
6102 ++m;
6103
6104 ++i;
6105 }
6106
6107 --i;
6108
6109 if(i==MAXMIDIS && m<index)
6110 return "(null)";
6111
6112 return tunes[i].title;
6113 }
6114
6115 /* ------- MIDI info stuff -------- */
6116
6117 char *text;
6118 midi_info *zmi;
6119 bool dialog_running;
6120 bool listening;
6121
6122 void get_info(int32_t index);
6123
6124 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6125 {
6126 int32_t d2 = d->d2;
6127 int32_t ret = jwin_droplist_proc(msg,d,c);
6128
6129 if(d2!=d->d2)
6130 {
6131 get_info(d->d2);
6132 }
6133
6134 return ret;
6135 }
6136
6137 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6138 {
6139 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6140
6141 int32_t ret = jwin_button_proc(msg,d,c);
6142
6143 if(ret == D_CLOSE)
6144 {
6145 // get current midi index
6146 int32_t index = (d+(d->d1))->d2;
6147 int32_t i=0, m=0;
6148
6149 while(m<=index && i<=MAXMIDIS)
6150 {
6151 if(tunes[i].data)
6152 ++m;
6153
6154 ++i;
6155 }
6156
6157 --i;
6158 jukebox(i);
6159 listening = true;
6160 ret = D_O_K;
6161 }
6162
6163 return ret;
6164 }
6165
6166 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6167 {
6168 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6169
6170 int32_t ret = jwin_button_proc(msg,d,c);
6171
6172 if(ret == D_CLOSE)
6173 {
6174 // get current midi index
6175 int32_t index = (d+(d->d1))->d2;
6176 int32_t i=0, m=0;
6177
6178 while(m<=index && i<=MAXMIDIS)
6179 {
6180 if(tunes[i].data)
6181 ++m;
6182
6183 ++i;
6184 }
6185
6186 --i;
6187
6188 char title[40] = "Save MIDI: ";
6189 static EXT_LIST list[] =
6190 {
6191 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6192 { NULL, NULL }
6193 };
6194
6195 strcpy(title+11, tunes[i].title);
6196 title[39] = '\0';
6197
6198 std::string fname;
6199 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6200 fname = *result;
6201 else
6202 goto done;
6203
6204 if(exists(fname.c_str()))
6205 {
6206 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6207 goto done;
6208 }
6209
6210 // save midi i
6211
6212 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6213 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6214
6215 done:
6216 chop_path(fname.data());
6217 ret = D_REDRAW;
6218 }
6219
6220 return ret;
6221 }
6222
6223 349 static ListData midi_list(midilist, &font);
6224
6225 static DIALOG midi_dlg[] =
6226 {
6227 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6228 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6229 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6230 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6231 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6232 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6233 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6234 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6235 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6236 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6237 };
6238
6239 void get_info(int32_t index)
6240 {
6241 int32_t i=0, m=0;
6242
6243 while(m<=index && i<=MAXMIDIS)
6244 {
6245 if(tunes[i].data)
6246 ++m;
6247
6248 ++i;
6249 }
6250
6251 --i;
6252
6253 if(i==MAXMIDIS && m<index)
6254 strcpy(text,"(null)");
6255 else
6256 {
6257 get_midi_info(tunes[i].data,zmi);
6258 get_midi_text(tunes[i].data,zmi,text);
6259 }
6260
6261 midi_dlg[0].dp2=get_zc_font(font_lfont);
6262 midi_dlg[3].dp = text;
6263 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6264 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6265
6266 if(dialog_running)
6267 {
6268 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6269 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6270 }
6271 }
6272
6273 int32_t onMIDICredits()
6274 {
6275 text = (char*)malloc(4096);
6276 zmi = (midi_info*)malloc(sizeof(midi_info));
6277
6278 if(!text || !zmi)
6279 {
6280 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6281 return D_O_K;
6282 }
6283
6284 bool do_pause_midi = midi_pos >= 0 && currmidi;
6285 auto restore_midi = currmidi;
6286 if(do_pause_midi)
6287 {
6288 paused_midi_pos = midi_pos;
6289 stop_midi();
6290 midi_suspended = midissuspHALTED;
6291 }
6292
6293 midi_dlg[0].dp2=get_zc_font(font_lfont);
6294 midi_dlg[2].d1 = 0;
6295 midi_dlg[2].d2 = 0;
6296 midi_dlg[4].flags = D_EXIT;
6297 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6298
6299 listening = false;
6300 dialog_running=false;
6301 get_info(0);
6302
6303 dialog_running=true;
6304
6305 large_dialog(midi_dlg);
6306
6307 do_zqdialog(midi_dlg,0);
6308 dialog_running=false;
6309
6310 if(listening)
6311 music_stop();
6312
6313 if(do_pause_midi)
6314 {
6315 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6316 midi_suspended = midissuspRESUME;
6317 currmidi = restore_midi;
6318 midi_pos = paused_midi_pos;
6319 }
6320
6321 if(text) free(text);
6322 if(zmi) free(zmi);
6323 return D_O_K;
6324 }
6325
6326 int32_t onAbout()
6327 {
6328 char buf1[80]={0};
6329 std::ostringstream oss;
6330 sprintf(buf1,ZC_PLAYER_NAME);
6331 oss << buf1 << '\n';
6332 sprintf(buf1,"Version: %s", getVersionString());
6333 oss << buf1 << '\n';
6334 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6335 oss << buf1 << '\n';
6336 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6337 oss << buf1 << '\n';
6338
6339 InfoDialog("About ZC", oss.str()).show();
6340 return D_O_K;
6341 }
6342
6343 int32_t onQuest()
6344 {
6345 char fname[100];
6346 strcpy(fname, get_filename(qstpath));
6347 quest_dlg[0].dp2=get_zc_font(font_lfont);
6348 quest_dlg[1].dp = fname;
6349
6350 if(QHeader.quest_number==0)
6351 sprintf(str_a,"Custom");
6352 else
6353 sprintf(str_a,"%d",QHeader.quest_number);
6354
6355 sprintf(str_s,"%s",QHeader.getVerStr());
6356
6357 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6358 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6359
6360 large_dialog(quest_dlg);
6361
6362 do_zqdialog(quest_dlg, 0);
6363 return D_O_K;
6364 }
6365
6366 void call_vidmode_dlg();
6367 int32_t onVidMode()
6368 {
6369 call_vidmode_dlg();
6370 return D_O_K;
6371 }
6372
6373 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6374 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6375 //Added an extra statement, so that if the key is cleared to 0, the cleared
6376 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6377
6378 void load_ukeys(int32_t* arr)
6379 {
6380 arr[ukey_a] = Akey;
6381 arr[ukey_b] = Bkey;
6382 arr[ukey_s] = Skey;
6383 arr[ukey_l] = Lkey;
6384 arr[ukey_r] = Rkey;
6385 arr[ukey_p] = Pkey;
6386 arr[ukey_ex1] = Exkey1;
6387 arr[ukey_ex2] = Exkey2;
6388 arr[ukey_ex3] = Exkey3;
6389 arr[ukey_ex4] = Exkey4;
6390 arr[ukey_du] = DUkey;
6391 arr[ukey_dd] = DDkey;
6392 arr[ukey_dl] = DLkey;
6393 arr[ukey_dr] = DRkey;
6394 arr[ukey_mod1a] = cheat_modifier_keys[0];
6395 arr[ukey_mod1b] = cheat_modifier_keys[1];
6396 arr[ukey_mod2a] = cheat_modifier_keys[2];
6397 arr[ukey_mod2b] = cheat_modifier_keys[3];
6398 };
6399
6400 static const char* ukey_names[] = {
6401 "A", "B", "Start", "L", "R", "Map",
6402 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6403 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6404 "Cheat Mod R1", "Cheat Mod R2",
6405 };
6406 std::string get_ukey_name(int32_t k)
6407 {
6408 if (k < num_ukey) return ukey_names[k];
6409 return "";
6410 }
6411
6412 int32_t onKeyboard()
6413 {
6414 int32_t a = Akey;
6415 int32_t b = Bkey;
6416 int32_t s = Skey;
6417 int32_t l = Lkey;
6418 int32_t r = Rkey;
6419 int32_t p = Pkey;
6420 int32_t ex1 = Exkey1;
6421 int32_t ex2 = Exkey2;
6422 int32_t ex3 = Exkey3;
6423 int32_t ex4 = Exkey4;
6424 int32_t du = DUkey;
6425 int32_t dd = DDkey;
6426 int32_t dl = DLkey;
6427 int32_t dr = DRkey;
6428 int32_t mod1a = cheat_modifier_keys[0];
6429 int32_t mod1b = cheat_modifier_keys[1];
6430 int32_t mod2a = cheat_modifier_keys[2];
6431 int32_t mod2b = cheat_modifier_keys[3];
6432 bool done=false;
6433 int32_t ret;
6434
6435 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6436
6437 large_dialog(keyboard_control_dlg);
6438
6439 while(!done)
6440 {
6441 ret = do_zqdialog(keyboard_control_dlg,3);
6442
6443 if(ret==3) // OK
6444 {
6445 int32_t ukeys[num_ukey];
6446 load_ukeys(ukeys);
6447 std::vector<std::string> uniqueError;
6448 for(int32_t q = 0; q < num_ukey; ++q)
6449 {
6450 for(int32_t p = q+1; p < num_ukey; ++p)
6451 {
6452 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6453 {
6454 char buf[64];
6455 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6456 std::string str(buf);
6457 uniqueError.push_back(str);
6458 }
6459 }
6460 }
6461 if(uniqueError.size() == 0)
6462 {
6463 done = true;
6464 save_control_configs(true);
6465 }
6466 else
6467 {
6468 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6469 box_out("Cannot have duplicate keybinds!"); box_eol();
6470 for(std::vector<std::string>::iterator it = uniqueError.begin();
6471 it != uniqueError.end(); ++it)
6472 {
6473 box_out((*it).c_str()); box_eol();
6474 }
6475 box_end(true);
6476 }
6477 }
6478 else // Cancel
6479 {
6480 Akey = a;
6481 Bkey = b;
6482 Skey = s;
6483 Lkey = l;
6484 Rkey = r;
6485 Pkey = p;
6486 Exkey1 = ex1;
6487 Exkey2 = ex2;
6488 Exkey3 = ex3;
6489 Exkey4 = ex4;
6490 DUkey = du;
6491 DDkey = dd;
6492 DLkey = dl;
6493 DRkey = dr;
6494 cheat_modifier_keys[0] = mod1a;
6495 cheat_modifier_keys[1] = mod1b;
6496 cheat_modifier_keys[2] = mod2a;
6497 cheat_modifier_keys[3] = mod2b;
6498
6499 done=true;
6500 }
6501
6502 rest(1);
6503 }
6504
6505 return D_O_K;
6506 }
6507
6508 int32_t onGamepad()
6509 {
6510 if (al_get_num_joysticks() == 0)
6511 {
6512 InfoDialog("ZC", "No gamepads detected.").show();
6513 return D_O_K;
6514 }
6515
6516 int32_t a = Abtn;
6517 int32_t b = Bbtn;
6518 int32_t s = Sbtn;
6519 int32_t l = Lbtn;
6520 int32_t r = Rbtn;
6521 int32_t m = Mbtn;
6522 int32_t p = Pbtn;
6523 int32_t ex1 = Exbtn1;
6524 int32_t ex2 = Exbtn2;
6525 int32_t ex3 = Exbtn3;
6526 int32_t ex4 = Exbtn4;
6527 int32_t up = DUbtn;
6528 int32_t down = DDbtn;
6529 int32_t left = DLbtn;
6530 int32_t right = DRbtn;
6531 int32_t joy = joystick_index;
6532 int32_t stick_1 = js_stick_1_x_stick;
6533 int32_t stick_2 = js_stick_2_x_stick;
6534
6535 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6536 if(analog_movement)
6537 gamepad_dlg[56].flags|=D_SELECTED;
6538 else
6539 gamepad_dlg[56].flags&=~D_SELECTED;
6540
6541 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6542 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6543 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6544 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6545 // requires remapping every time.
6546 if (joystick_index >= al_get_num_joysticks())
6547 joystick_index = 0;
6548 gamepad_dlg[61].d2 = joystick_index;
6549
6550 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6551 if (!gamepad_dlg_cur_joystick)
6552 {
6553 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6554 return D_CLOSE;
6555 }
6556
6557 large_dialog(gamepad_dlg);
6558
6559 int32_t ret = do_zqdialog(gamepad_dlg,4);
6560
6561 if(ret == 4) //OK
6562 {
6563 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6564 joystick_index = gamepad_dlg[61].d2;
6565 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6566 if (!gamepad_dlg_cur_joystick)
6567 {
6568 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6569 return D_CLOSE;
6570 }
6571 js_stick_1_y_stick = js_stick_1_x_stick;
6572 js_stick_2_y_stick = js_stick_2_x_stick;
6573 save_control_configs(false);
6574 }
6575 else //Cancel
6576 {
6577 Abtn = a;
6578 Bbtn = b;
6579 Sbtn = s;
6580 Lbtn = l;
6581 Rbtn = r;
6582 Mbtn = m;
6583 Pbtn = p;
6584 Exbtn1 = ex1;
6585 Exbtn2 = ex2;
6586 Exbtn3 = ex3;
6587 Exbtn4 = ex4;
6588 DUbtn = up;
6589 DDbtn = down;
6590 DLbtn = left;
6591 DRbtn = right;
6592 joystick_index = joy;
6593 js_stick_1_x_stick = stick_1;
6594 js_stick_2_x_stick = stick_2;
6595 }
6596
6597 return D_O_K;
6598 }
6599
6600 int32_t onCheatKeys()
6601 {
6602 int32_t oldcheats[Cheat::Last][2];
6603 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6604
6605 bool done=false;
6606
6607 while(!done)
6608 {
6609 bool confirm = false;
6610 CheatKeysDialog(&confirm).show();
6611 if(confirm) // OK
6612 {
6613 std::vector<std::string> uniqueError;
6614 char buf[512];
6615 for(size_t q = 1; q < Cheat::Last; ++q)
6616 {
6617 if(cheatkeys[q][1] && !cheatkeys[q][0])
6618 {
6619 cheatkeys[q][0] = cheatkeys[q][1];
6620 cheatkeys[q][1] = 0;
6621 }
6622 }
6623 for(size_t q = 1; q < Cheat::Last; ++q)
6624 {
6625 if(!bindable_cheat((Cheat)q)) continue;
6626 for(size_t p = q+1; p < Cheat::Last; ++p)
6627 {
6628 if(!bindable_cheat((Cheat)p)) continue;
6629 for(size_t q2 = 0; q2 <= 1; ++q2)
6630 for(size_t p2 = 0; p2 <= 1; ++p2)
6631 {
6632 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6633 {
6634 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6635 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6636 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6637 get_keystr(cheatkeys[q][q2])));
6638 }
6639 }
6640 }
6641 }
6642 if(uniqueError.size() == 0)
6643 {
6644 done = true;
6645 save_cheatkeys();
6646 }
6647 else
6648 {
6649 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6650 box_out("Cannot have duplicate keybinds!"); box_eol();
6651 for(std::vector<std::string>::iterator it = uniqueError.begin();
6652 it != uniqueError.end(); ++it)
6653 {
6654 box_out((*it).c_str()); box_eol();
6655 }
6656 box_end(true);
6657 }
6658 }
6659 else // Cancel
6660 {
6661 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6662 done=true;
6663 }
6664 rest(1);
6665 }
6666
6667 return D_O_K;
6668 }
6669
6670 int32_t onSound()
6671 {
6672 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6673 {
6674 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6675 {
6676 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6677 }
6678 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6679 {
6680 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6681 }
6682 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6683 {
6684 emusic_volume = (int32_t)FFCore.usr_music_volume;
6685 }
6686 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6687 {
6688 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6689 }
6690 }
6691 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6692 {
6693 pan_style = (int32_t)FFCore.usr_panstyle;
6694 }
6695
6696 int32_t m = midi_volume;
6697 int32_t e = emusic_volume;
6698 int32_t s = sfx_volume;
6699 int32_t p = pan_style;
6700 pan_style = vbound(pan_style,0,3);
6701
6702 sound_dlg[0].dp2=get_zc_font(font_lfont);
6703
6704 large_dialog(sound_dlg);
6705
6706 midi_dp[1] = sound_dlg[6].x;
6707 midi_dp[2] = sound_dlg[6].y;
6708 emus_dp[1] = sound_dlg[8].x;
6709 emus_dp[2] = sound_dlg[8].y;
6710 sfx_dp[1] = sound_dlg[10].x;
6711 sfx_dp[2] = sound_dlg[10].y;
6712 pan_dp[1] = sound_dlg[11].x;
6713 pan_dp[2] = sound_dlg[11].y;
6714 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6715 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6716 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6717 sound_dlg[20].d2 = pan_style;
6718
6719 int32_t ret = do_zqdialog(sound_dlg,1);
6720
6721 if(ret==2)
6722 {
6723 master_volume(digi_volume,midi_volume);
6724 if (zcmusic)
6725 zcmusic_set_volume(zcmusic, emusic_volume);
6726
6727 int32_t temp_volume = sfx_volume;
6728 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6729 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6730 for(int32_t i=0; i<WAV_COUNT; ++i)
6731 {
6732 if(sfx_voice[i] >= 0)
6733 voice_set_volume(sfx_voice[i], temp_volume);
6734 }
6735 zc_set_config(sfx_sect,"midi",midi_volume);
6736 zc_set_config(sfx_sect,"sfx",sfx_volume);
6737 zc_set_config(sfx_sect,"emusic",emusic_volume);
6738 zc_set_config(sfx_sect,"pan",pan_style);
6739 }
6740 else
6741 {
6742 midi_volume = m;
6743 emusic_volume = e;
6744 sfx_volume = s;
6745 pan_style = p;
6746 }
6747
6748 return D_O_K;
6749 }
6750
6751 int32_t queding(char const* s1, char const* s2, char const* s3)
6752 {
6753 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6754 }
6755
6756 int32_t onQuit()
6757 {
6758 if(Playing)
6759 {
6760 int32_t ret=0;
6761
6762 if(get_qr(qr_NOCONTINUE))
6763 {
6764 if(standalone_mode)
6765 {
6766 ret=queding("End current game?",
6767 "The continue screen is disabled; the game",
6768 "will be reloaded from the last save.");
6769 }
6770 else
6771 {
6772 ret=queding("End current game?",
6773 "The continue screen is disabled. You will",
6774 "be returned to the file select screen.");
6775 }
6776 }
6777 else
6778 ret=queding("End current game?",NULL,NULL);
6779
6780 if(ret==1)
6781 {
6782 disableClickToFreeze=false;
6783 Quit=qQUIT;
6784
6785 // Trying to evade a door repair charge?
6786 if(repaircharge)
6787 {
6788 game->change_drupy(-repaircharge);
6789 repaircharge=0;
6790 }
6791
6792 return D_CLOSE;
6793 }
6794 }
6795
6796 return D_O_K;
6797 }
6798
6799 int32_t onTryQuitMenu()
6800 {
6801 return onTryQuit(true);
6802 }
6803
6804 int32_t onTryQuit(bool inMenu)
6805 {
6806 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6807 {
6808 if(active_cutscene.can_f6())
6809 {
6810 if(get_qr(qr_OLD_F6))
6811 {
6812 if(inMenu) onQuit();
6813 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6814 }
6815 else
6816 {
6817 disableClickToFreeze=false;
6818 GameFlags |= GAMEFLAG_TRYQUIT;
6819 }
6820 return D_CLOSE;
6821 }
6822 else active_cutscene.error();
6823 }
6824
6825 return D_O_K;
6826 }
6827
6828 int32_t onReset()
6829 {
6830 if(queding(" Reset system? ",NULL,NULL)==1)
6831 {
6832 disableClickToFreeze=false;
6833 Quit=qRESET;
6834 replay_quit();
6835 return D_CLOSE;
6836 }
6837
6838 return D_O_K;
6839 }
6840
6841 int32_t onExit()
6842 {
6843 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6844 {
6845 Quit=qEXIT;
6846 return D_CLOSE;
6847 }
6848
6849 return D_O_K;
6850 }
6851
6852 int32_t onDebug()
6853 {
6854 if(debug_enabled)
6855 set_debug(!get_debug());
6856 return D_O_K;
6857 }
6858
6859 int32_t onHeartBeep()
6860 {
6861 heart_beep=!heart_beep;
6862 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6863 return D_O_K;
6864 }
6865
6866 int32_t onSaveIndicator()
6867 {
6868 use_save_indicator = use_save_indicator ? 0 : 1;
6869 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6870 return D_O_K;
6871 }
6872
6873 int32_t onEpilepsy()
6874 {
6875 if(jwin_alert3(
6876 "Epilepsy Flash Reduction",
6877 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6878 "Disabling this will restore standard flash and wavy behaviour.",
6879 "Proceed?",
6880 "&Yes",
6881 "&No",
6882 NULL,
6883 'y',
6884 'n',
6885 0,
6886 get_zc_font(font_lfont)) == 1)
6887 {
6888 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6889 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6890 }
6891 return D_O_K;
6892 }
6893
6894 bool rc = false;
6895
6896 static DIALOG getnum_dlg[] =
6897 {
6898 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6899 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6900 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6901 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6902 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6903 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6904 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6905 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6906 };
6907
6908 int32_t getnumber(const char *prompt,int32_t initialval)
6909 {
6910 char buf[20];
6911 sprintf(buf,"%d",initialval);
6912 getnum_dlg[0].dp=(void *)prompt;
6913 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6914 getnum_dlg[2].dp=buf;
6915
6916 large_dialog(getnum_dlg);
6917
6918 if(do_zqdialog(getnum_dlg,2)==3)
6919 return atoi(buf);
6920
6921 return initialval;
6922 }
6923
6924 int32_t onLife()
6925 {
6926 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6927 cheats_enqueue(Cheat::Life, value);
6928 return D_O_K;
6929 }
6930
6931 int32_t onHeartC()
6932 {
6933 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6934 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6935 cheats_enqueue(Cheat::MaxLife, max_life);
6936 cheats_enqueue(Cheat::Life, life);
6937 return D_O_K;
6938 }
6939
6940 int32_t onMagicC()
6941 {
6942 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6943 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6944 cheats_enqueue(Cheat::MaxMagic, max_magic);
6945 cheats_enqueue(Cheat::Magic, magic);
6946 return D_O_K;
6947 }
6948
6949 int32_t onRupies()
6950 {
6951 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6952 cheats_enqueue(Cheat::Rupies, value);
6953 return D_O_K;
6954 }
6955
6956 int32_t onMaxBombs()
6957 {
6958 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6959 cheats_enqueue(Cheat::MaxBombs, value);
6960 cheats_enqueue(Cheat::Bombs, value);
6961 return D_O_K;
6962 }
6963
6964 int32_t onRefillLife()
6965 {
6966 cheats_enqueue(Cheat::Life, game->get_maxlife());
6967 return D_O_K;
6968 }
6969 int32_t onRefillMagic()
6970 {
6971 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6972 return D_O_K;
6973 }
6974 int32_t onClock()
6975 {
6976 cheats_enqueue(Cheat::Clock);
6977 return D_O_K;
6978 }
6979
6980 int32_t onQstPath()
6981 {
6982 char initial_path[2048];
6983 chop_path(qstdir);
6984 strcpy(initial_path, qstdir);
6985
6986 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
6987 {
6988 char* path = result->data();
6989 chop_path(path);
6990 fix_filename_case(path);
6991 fix_filename_slashes(path);
6992 strcpy(qstdir,path);
6993 strcpy(qstpath,qstdir);
6994 zc_set_config("zeldadx","quest_dir",qstdir);
6995 flush_config_file();
6996 }
6997
6998 return D_O_K;
6999 }
7000
7001 #include "dialog/cheat_dialog.h"
7002 int32_t onCheat()
7003 {
7004 call_setcheat_dialog();
7005 game->set_cheat(maxcheat);
7006 if(cheat) game->did_cheat(true);
7007 return D_O_K;
7008 }
7009
7010 int32_t onCheatRupies()
7011 {
7012 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7013 return D_O_K;
7014 }
7015
7016 int32_t onCheatArrows()
7017 {
7018 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7019 return D_O_K;
7020 }
7021
7022 int32_t onCheatBombs()
7023 {
7024 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7025 return D_O_K;
7026 }
7027
7028 // *** screen saver
7029
7030 18305549 int32_t after_time()
7031 {
7032
1/2
✓ Branch 0 taken 18305549 times.
✗ Branch 1 not taken.
18305549 if(ss_enable == 0)
7033 return INT_MAX;
7034
7035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
18305549 if(ss_after <= 0)
7036 return 5 * 60;
7037
7038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
18305549 if(ss_after <= 3)
7039 return ss_after * 15 * 60;
7040
7041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305549 times.
18305549 if(ss_after <= 13)
7042 return (ss_after - 3) * 60 * 60;
7043
7044 18305549 return MAX_IDLE + 1;
7045 18305549 }
7046
7047 static const char *after_str[15] =
7048 {
7049 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7050 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7051 "Never"
7052 };
7053
7054 const char *after_list(int32_t index, int32_t *list_size)
7055 {
7056 if(index < 0)
7057 {
7058 *list_size = 15;
7059 return NULL;
7060 }
7061
7062 return after_str[index];
7063 }
7064
7065 349 static ListData after__list(after_list, &font);
7066
7067 static DIALOG scrsaver_dlg[] =
7068 {
7069 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7070 349 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7071 349 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7072 349 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7073 349 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7074 349 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7075 349 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7076 349 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7077 349 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7078 349 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7079 349 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7080 349 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7081 349 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7082 349 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7083 };
7084
7085 int32_t onScreenSaver()
7086 {
7087 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7088 int32_t oldcfgs[3];
7089 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7090 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7091 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7092
7093 large_dialog(scrsaver_dlg);
7094
7095 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7096
7097 if(ret == 8 || ret == 9)
7098 {
7099 ss_after = scrsaver_dlg[5].d1;
7100 ss_speed = scrsaver_dlg[6].d2;
7101 ss_density = scrsaver_dlg[7].d2;
7102 if(oldcfgs[0] != ss_after)
7103 zc_set_config(cfg_sect,"ss_after",ss_after);
7104 if(oldcfgs[1] != ss_speed)
7105 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7106 if(oldcfgs[2] != ss_density)
7107 zc_set_config(cfg_sect,"ss_density",ss_density);
7108 }
7109
7110 if(ret == 9)
7111 // preview Screen Saver
7112 {
7113 clear_keybuf();
7114 Matrix(ss_speed, ss_density, 30);
7115 system_pal(true);
7116 sys_mouse();
7117 }
7118
7119 return D_O_K;
7120 }
7121
7122 /***** Menus *****/
7123
7124 enum
7125 {
7126 MENUID_GAME_LOADQUEST,
7127 MENUID_GAME_ENDGAME,
7128 };
7129
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu game_menu
7130 2792 {
7131
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "&Continue","ESC", onContinue },
7132
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7133
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7134
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7135
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7136 #ifdef __EMSCRIPTEN__
7137 { "&Reset","F7", onReset },
7138 #elif defined(ALLEGRO_MACOSX)
7139 { "&Reset","F7", onReset },
7140 { "&Quit","F8", onExit },
7141 #else
7142
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "&Reset","F9", onReset },
7143
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "&Quit","F10", onExit },
7144 #endif
7145 };
7146
7147
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu snapshot_format_menu
7148 2443 {
7149
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7150
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7151
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7152
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7153
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7154
4/8
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349 times.
✗ Branch 7 not taken.
349 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7155 };
7156
7157
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu controls_menu
7158 1396 {
7159
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Key&board...", onKeyboard },
7160
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Gamepad...", onGamepad },
7161
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Cheat Keys...", onCheatKeys },
7162 };
7163
7164
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu name_entry_mode_menu
7165 1396 {
7166
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Keyboard", onKeyboardEntry },
7167
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Letter Grid", onLetterGridEntry },
7168
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Extended Letter Grid", onExtLetterGridEntry },
7169 };
7170
7171 static void set_controls_menu_active()
7172 {
7173
7174 }
7175
7176 enum
7177 {
7178 MENUID_WINDOW_LOCK_ASPECT,
7179 MENUID_WINDOW_LOCK_INTSCALE,
7180 MENUID_WINDOW_SAVE_SIZE,
7181 MENUID_WINDOW_SAVE_POS,
7182 MENUID_WINDOW_STRETCH,
7183 };
7184
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu window_menu
7185 2094 {
7186
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7187
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7188
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7189
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7190
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7191 };
7192 void call_zc_options_dlg();
7193 enum
7194 {
7195 MENUID_OPTIONS_PAUSE_BG,
7196 MENUID_OPTIONS_EPILEPSYPROT,
7197 };
7198
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu options_menu
7199 2443 {
7200
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Name &Entry Mode", &name_entry_mode_menu },
7201
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "S&napshot Format", &snapshot_format_menu },
7202
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Window Settings", &window_menu },
7203
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7204
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7205
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "More Options", call_zc_options_dlg },
7206 };
7207 enum
7208 {
7209 MENUID_SETTINGS_CONTROLS,
7210 MENUID_SETTINGS_CAPFPS,
7211 MENUID_SETTINGS_SHOWFPS,
7212 MENUID_SETTINGS_SHOWTIME,
7213 MENUID_SETTINGS_CLICK_FREEZE,
7214 MENUID_SETTINGS_TRANSLAYERS,
7215 MENUID_SETTINGS_NESQUIT,
7216 MENUID_SETTINGS_VOLKEYS,
7217 MENUID_SETTINGS_HEARTBEEP,
7218 MENUID_SETTINGS_SAVEINDICATOR,
7219 MENUID_SETTINGS_DEBUG,
7220 };
7221
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu settings_menu
7222 5933 {
7223
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Sound...", onSound },
7224
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7225
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7226
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Options", &options_menu },
7227
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7228
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7229
3/6
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 349 times.
✗ Branch 5 not taken.
349 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7230
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7231
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7232
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7233
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7234
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7235
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7236
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7237
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7238
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7239 };
7240
7241 enum
7242 {
7243 MENUID_MISC_FULLSCREEN,
7244 MENUID_MISC_VIDMODE,
7245 MENUID_MISC_QUEST_INFO,
7246 MENUID_MISC_QUEST_DIR,
7247 MENUID_MISC_CONSOLE,
7248 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7249 };
7250
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu misc_menu
7251 5235 {
7252
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&About...", onAbout },
7253 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7254 // { "&Credits...", onCredits },
7255
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7256
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7257
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7258
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7259
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Quest &MIDI Info...", onMIDICredits },
7260
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7261
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7262
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Take &Snapshot F12", onSnapshot },
7263
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Sc&reen Saver...", onScreenSaver },
7264
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Save ZC Configuration", OnSaveZCConfig },
7265
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7266
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7267
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Clear Directory Cache", OnnClearQuestDir },
7268 };
7269
7270 enum
7271 {
7272 MENUID_REFILL_ARROWS,
7273 };
7274
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu refill_menu
7275 2094 {
7276
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Life", onRefillLife },
7277
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Magic", onRefillMagic },
7278
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Bombs", onCheatBombs },
7279
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Rupees", onCheatRupies },
7280
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7281 };
7282
7283 enum
7284 {
7285 MENUID_SHOW_L0,
7286 MENUID_SHOW_L1,
7287 MENUID_SHOW_L2,
7288 MENUID_SHOW_L3,
7289 MENUID_SHOW_L4,
7290 MENUID_SHOW_L5,
7291 MENUID_SHOW_L6,
7292 MENUID_SHOW_OVER,
7293 MENUID_SHOW_PUSH,
7294 MENUID_SHOW_FFC,
7295 MENUID_SHOW_SPR,
7296 MENUID_SHOW_SCRIPTNAME,
7297 MENUID_SHOW_SOLIDITY,
7298 MENUID_SHOW_HITBOX,
7299 MENUID_SHOW_EFFECT,
7300 };
7301
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu show_menu
7302 6631 {
7303
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7304
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7305
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7306
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7307
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7308
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7309
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7310
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7311
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7312
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7313
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7314
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7315
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7316
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 {},
7317
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7318
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7319
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7320
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Info Opacity", onShowInfoOpacity },
7321 };
7322
7323 enum
7324 {
7325 MENUID_CHEAT_CHOP_L1,
7326 MENUID_CHEAT_CHOP_L2,
7327 MENUID_CHEAT_CHOP_L3,
7328 MENUID_CHEAT_CHOP_L4,
7329 MENUID_CHEAT_INVULN,
7330 MENUID_CHEAT_NOCLIP,
7331 MENUID_CHEAT_IGNORESV,
7332 MENUID_CHEAT_GOFAST,
7333 };
7334
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 static NewMenu cheat_menu
7335 5933 {
7336
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Set &Cheat", onCheat },
7337
1/2
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
349 { MENUID_CHEAT_CHOP_L1 },
7338
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Re&fill", &refill_menu },
7339
1/2
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
349 { MENUID_CHEAT_CHOP_L2 },
7340
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7341
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Ma&x Bombs...", onMaxBombs },
7342
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Heart Containers...", onHeartC },
7343
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Magic Containers...", onMagicC },
7344
1/2
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
349 { MENUID_CHEAT_CHOP_L3 },
7345
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Player Data...", onCheatConsole },
7346
1/2
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
349 { MENUID_CHEAT_CHOP_L4 },
7347
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7348
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Player Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7349
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7350
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Kill All Enemies", onKillCheat },
7351
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Trigger &Secrets", onSecretsCheat },
7352
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Trigger Secrets Perm", onSecretsCheatPerm },
7353
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Show/Hide Layer", &show_menu },
7354
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "Toggle &Light", onLightSwitch },
7355
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Goto Location...", onGoTo },
7356 };
7357
7358 #if DEVLEVEL > 0
7359 int32_t devLogging();
7360 int32_t devDebug();
7361 int32_t devTimestmp();
7362 #if DEVLEVEL > 1
7363 int32_t setCheat();
7364 #endif //DEVLEVEL > 1
7365 enum
7366 {
7367 MENUID_DEV_LOGGING,
7368 MENUID_DEV_DEBUG,
7369 MENUID_DEV_TIMESTAMP,
7370 MENUID_DEV_SETCHEAT,
7371 };
7372 static NewMenu dev_menu
7373 {
7374 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7375 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7376 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7377 #if DEVLEVEL > 1
7378 {},
7379 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7380 #endif //DEVLEVEL > 1
7381 };
7382 int32_t devLogging()
7383 {
7384 dev_logging = !dev_logging;
7385 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7386 return D_O_K;
7387 }
7388 // int32_t devDebug()
7389 // {
7390 // dev_debug = !dev_debug;
7391 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7392 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7393 // return D_O_K;
7394 // }
7395 int32_t devTimestmp()
7396 {
7397 dev_timestmp = !dev_timestmp;
7398 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7399 return D_O_K;
7400 }
7401 #if DEVLEVEL > 1
7402 int32_t setCheat()
7403 {
7404 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7405 return D_O_K;
7406 }
7407 #endif //DEVLEVEL > 1
7408 #endif //DEVLEVEL > 0
7409
7410 enum
7411 {
7412 MENUID_PLAYER_CHEAT,
7413 };
7414
1/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
349 TopMenu the_player_menu
7415 2094 {
7416
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Game", &game_menu },
7417
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Settings", &settings_menu },
7418
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7419
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&Replay", &replay_menu },
7420
2/4
✓ Branch 0 taken 349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 349 times.
✗ Branch 3 not taken.
349 { "&ZC", &misc_menu },
7421 #if DEVLEVEL > 0
7422 { "&Dev", &dev_menu },
7423 #endif
7424 };
7425
7426 int32_t onPauseInBackground()
7427 {
7428 if(jwin_alert3(
7429 "Toggle Pause In Background",
7430 "This action will change whether ZC Player pauses when the window loses focus.",
7431 "",
7432 "Proceed?",
7433 "&Yes",
7434 "&No",
7435 NULL,
7436 'y',
7437 'n',
7438 0,
7439 get_zc_font(font_lfont)) == 1)
7440 {
7441 pause_in_background = pause_in_background ? 0 : 1;
7442 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7443 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7444 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7445 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7446 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7447 }
7448 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7449 return D_O_K;
7450 }
7451
7452 int32_t onKeyboardEntry()
7453 {
7454 NameEntryMode=0;
7455 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7456 return D_O_K;
7457 }
7458
7459 int32_t onLetterGridEntry()
7460 {
7461 NameEntryMode=1;
7462 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7463 return D_O_K;
7464 }
7465
7466 int32_t onExtLetterGridEntry()
7467 {
7468 NameEntryMode=2;
7469 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7470 return D_O_K;
7471 }
7472
7473 static BITMAP* oldscreen;
7474 int32_t onFullscreenMenu()
7475 {
7476 PALETTE oldpal;
7477 get_palette(oldpal);
7478
7479 fullscreen = !fullscreen;
7480 all_toggle_fullscreen(fullscreen);
7481 zc_set_config("zeldadx","fullscreen",fullscreen);
7482
7483 zc_set_palette(oldpal);
7484 gui_mouse_focus=0;
7485 extern int32_t switch_type;
7486 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7487 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7488 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7489 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7490 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7491 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7492
7493 return D_O_K;
7494 }
7495
7496 259 void fix_menu()
7497 {
7498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if(!debug_enabled)
7499 259 settings_menu.chop_index = 13;
7500 259 }
7501
7502 int32_t onSetSnapshotFormat(SnapshotType format)
7503 {
7504 SnapshotFormat = format;
7505 zc_set_config("zeldadx", "snapshot_format", format);
7506 snapshot_format_menu.select_only_index(format);
7507 return D_O_K;
7508 }
7509
7510
7511 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7512 {
7513 PALETTE tmp;
7514
7515 for(int32_t i=0; i<256; i++)
7516 {
7517 tmp[i].r=r;
7518 tmp[i].g=g;
7519 tmp[i].b=b;
7520 }
7521
7522 fade_interpolate(src,tmp,dest,pos,from,to);
7523 }
7524
7525 55 void system_pal(bool force)
7526 {
7527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 if(is_sys_pal && !force) return;
7528 55 is_sys_pal = true;
7529 55 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7530 55 hw_palette = &syspal;
7531 55 update_hw_pal = true;
7532 55 }
7533
7534 static uint32_t entered_sys_pal = 0;
7535 55 void enter_sys_pal()
7536 {
7537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(is_sys_pal)
7538 {
7539 if(entered_sys_pal)
7540 ++entered_sys_pal;
7541 return;
7542 }
7543 55 sys_mouse();
7544 55 system_pal(true);
7545 55 ++entered_sys_pal;
7546 55 }
7547 55 void exit_sys_pal()
7548 {
7549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(entered_sys_pal)
7550 {
7551
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(!--entered_sys_pal)
7552 {
7553 55 game_pal();
7554 55 game_mouse();
7555 55 }
7556 55 }
7557 55 }
7558
7559 void switch_out_callback()
7560 {
7561 if (pause_in_background && !MenuOpen)
7562 {
7563 System();
7564 }
7565 }
7566
7567 void switch_in_callback()
7568 {
7569 }
7570
7571 1093 void game_pal()
7572 {
7573 1093 is_sys_pal = false;
7574 1093 entered_sys_pal = 0;
7575 1093 hw_palette = &RAMpal;
7576 1093 update_hw_pal = true;
7577 1093 }
7578
7579 static char bar_str[] = "";
7580
7581 55 void music_pause()
7582 {
7583 //al_pause_duh(tmplayer);
7584 55 zcmusic_pause(zcmusic, ZCM_PAUSE);
7585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(zcmixer->oldtrack)
7586 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7587 55 zc_midi_pause();
7588 55 }
7589
7590 void music_resume()
7591 {
7592 //al_resume_duh(tmplayer);
7593 zcmusic_pause(zcmusic, ZCM_RESUME);
7594 if (zcmixer->oldtrack)
7595 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7596 zc_midi_resume();
7597 }
7598
7599 7783 void music_stop()
7600 {
7601 //al_stop_duh(tmplayer);
7602 //unload_duh(tmusic);
7603 //tmusic=NULL;
7604 //tmplayer=NULL;
7605 7783 zcmusic_stop(zcmusic);
7606 7783 zcmusic_unload_file(zcmusic);
7607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7783 times.
7783 if (zcmixer->oldtrack)
7608 {
7609 zcmusic_stop(zcmixer->oldtrack);
7610 zcmusic_unload_file(zcmixer->oldtrack);
7611 }
7612 7783 zcmixer->newtrack = NULL;
7613 7783 zc_stop_midi();
7614 7783 currmidi=-1;
7615 7783 }
7616
7617 bool reload_fonts = false;
7618 void System()
7619 {
7620 mouse_down = gui_mouse_b();
7621 music_pause();
7622 pause_all_sfx();
7623 MenuOpen = true;
7624 enter_sys_pal();
7625 // FONT *oldfont=font;
7626 // font=tfont;
7627
7628 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7629 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7630
7631 #if DEVLEVEL > 1
7632 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7633 #endif
7634 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7635 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7636 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7637 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7638 clear_keybuf();
7639
7640 clear_bitmap(menu_bmp);
7641 oldscreen = screen;
7642 screen = menu_bmp;
7643
7644 the_player_menu.reset_state();
7645 the_player_menu.position(0, 0);
7646
7647 bool running = true;
7648 bool esc = key[KEY_ESC] || cMbtn();
7649 bool autopop = esc;
7650 do
7651 {
7652 if(reload_fonts)
7653 {
7654 init_custom_fonts();
7655 clear_bitmap(menu_bmp);
7656 broadcast_dialog_message(MSG_DRAW, 0);
7657 reload_fonts = false;
7658 }
7659 if(handle_close_btn_quit())
7660 break;
7661
7662 //update submenus
7663 {
7664 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7665 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7666 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7667 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7668 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7669 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7670 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7671 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7672
7673 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7674 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7675 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7676 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7677 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7678
7679 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7680 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7681
7682 name_entry_mode_menu.select_only_index(NameEntryMode);
7683
7684 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7685 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7686
7687 bool nocheat = (replay_is_replaying() || !Playing
7688 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7689 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7690 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7691 cheat_menu.chop_index.reset();
7692 if(cheat < 4)
7693 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7694 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7695 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7696 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7697 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7698
7699 show_menu.select_uid(MENUID_SHOW_L0, show_layer_0);
7700 show_menu.select_uid(MENUID_SHOW_L1, show_layer_1);
7701 show_menu.select_uid(MENUID_SHOW_L2, show_layer_2);
7702 show_menu.select_uid(MENUID_SHOW_L3, show_layer_3);
7703 show_menu.select_uid(MENUID_SHOW_L4, show_layer_4);
7704 show_menu.select_uid(MENUID_SHOW_L5, show_layer_5);
7705 show_menu.select_uid(MENUID_SHOW_L6, show_layer_6);
7706 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7707 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7708 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7709 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7710 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7711 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7712 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7713 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7714
7715 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7716 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7717
7718 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7719 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7720
7721 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7722 #ifdef HAS_CURL
7723 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7724 #endif
7725 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7726 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7727 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7728
7729 snapshot_format_menu.select_only_index(SnapshotFormat);
7730 }
7731
7732 if(debug_enabled)
7733 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7734
7735 if(autopop)
7736 clear_keybuf();
7737 the_player_menu.run(true);
7738 if(autopop)
7739 {
7740 the_player_menu.pop_sub(0, &the_player_menu);
7741 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7742 autopop = false;
7743 update_hw_screen();
7744 }
7745
7746 update_hw_screen();
7747
7748 auto mb = gui_mouse_b();
7749 if(XOR(mb, mouse_down))
7750 {
7751 if(!the_player_menu.has_mouse())
7752 if(mb)
7753 break;
7754 mouse_down = mb;
7755 }
7756
7757 if(input_idle(true) > after_time())
7758 // run Screeen Saver
7759 {
7760 // Screen saver enabled for now.
7761 clear_keybuf();
7762 Matrix(ss_speed, ss_density, 0);
7763 system_pal(true);
7764 sys_mouse();
7765 }
7766
7767 poll_keyboard();
7768 if(esc)
7769 {
7770 if(!key[KEY_ESC])
7771 esc = false;
7772 }
7773
7774 if(keypressed() && !CHECK_ALT) //System hotkeys
7775 {
7776 auto c = peekkey();
7777 bool eatkey = true;
7778 switch(c>>8)
7779 {
7780 //Spare keys used by the menu
7781 case KEY_UP:
7782 case KEY_DOWN:
7783 case KEY_LEFT:
7784 case KEY_RIGHT:
7785 eatkey = false;
7786 break;
7787 case KEY_F1:
7788 onThrottleFPS();
7789 break;
7790 case KEY_F2:
7791 onShowFPS();
7792 break;
7793 case KEY_F6:
7794 onTryQuitMenu();
7795 break;
7796 #ifndef ALLEGRO_MACOSX
7797 case KEY_F9:
7798 onReset();
7799 break;
7800 case KEY_F10:
7801 onExit();
7802 break;
7803 #else
7804 case KEY_F7:
7805 onReset();
7806 break;
7807 case KEY_F8:
7808 onExit();
7809 break;
7810 #endif
7811 case KEY_F12:
7812 onSnapshot();
7813 break;
7814 case KEY_TAB:
7815 onDebug();
7816 break;
7817 case KEY_ESC:
7818 if(!esc)
7819 running = false;
7820 break;
7821 }
7822 if(eatkey)
7823 readkey();
7824 }
7825 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7826 break;
7827 }
7828 while(running);
7829
7830 screen = oldscreen;
7831
7832 mouse_down=gui_mouse_b();
7833 MenuOpen = false;
7834 if(Quit)
7835 {
7836 kill_sfx();
7837 music_stop();
7838 update_hw_screen();
7839 }
7840 else
7841 {
7842 music_resume();
7843 resume_all_sfx();
7844
7845 if(rc)
7846 ringcolor(false);
7847 }
7848 exit_sys_pal();
7849
7850 eat_buttons();
7851
7852 rc=false;
7853 clear_keybuf();
7854
7855 zc_init_apply_cheat_delta();
7856 }
7857
7858 259 void fix_dialogs()
7859 {
7860 259 jwin_center_dialog(about_dlg);
7861 259 jwin_center_dialog(gamepad_dlg);
7862 259 jwin_center_dialog(credits_dlg);
7863 259 jwin_center_dialog(gamemode_dlg);
7864 259 jwin_center_dialog(getnum_dlg);
7865 259 jwin_center_dialog(goto_dlg);
7866 259 jwin_center_dialog(keyboard_control_dlg);
7867 259 jwin_center_dialog(midi_dlg);
7868 259 jwin_center_dialog(quest_dlg);
7869 259 jwin_center_dialog(scrsaver_dlg);
7870 259 jwin_center_dialog(sound_dlg);
7871 259 jwin_center_dialog(triforce_dlg);
7872 259 }
7873
7874 4275 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7875 {
7876
3/4
✓ Branch 0 taken 4275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4253 times.
✓ Branch 3 taken 22 times.
4275 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7877 }
7878
7879 289 int32_t get_emusic_volume()
7880 {
7881 289 int32_t temp_volume = emusic_volume;
7882
2/4
✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 289 times.
✗ Branch 3 not taken.
289 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7883 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 289 times.
289 if (!zcmusic)
7885 289 return temp_volume;
7886 return (temp_volume * zcmusic->fadevolume) / 10000;
7887 289 }
7888
7889 int32_t get_zcmusicpos()
7890 {
7891 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7892 return debugtracething;
7893 return 0;
7894 }
7895
7896 void set_zcmusicpos(int32_t position)
7897 {
7898 zcmusic_set_curpos(zcmusic, position);
7899 }
7900
7901 void set_zcmusicspeed(int32_t speed)
7902 {
7903 zcmusic_set_speed(zcmusic, speed);
7904 }
7905
7906 int32_t get_zcmusiclen()
7907 {
7908 return zcmusic_get_length(zcmusic);
7909 }
7910
7911 3 void set_zcmusicloop(double start, double end)
7912 {
7913 3 zcmusic_set_loop(zcmusic, start, end);
7914 3 }
7915
7916 64156 void jukebox(int32_t index,int32_t loop)
7917 {
7918
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if (is_headless())
7919 64156 return;
7920
7921 music_stop();
7922
7923 if(index<0) index=MAXMIDIS-1;
7924
7925 if(index>=MAXMIDIS) index=0;
7926
7927 music_stop();
7928
7929 // Allegro's DIGMID driver (the one normally used on on Linux) gets
7930 // stuck notes when a song stops. This fixes it.
7931 if(strcmp(midi_driver->name, "DIGMID")==0)
7932 zc_set_volume(0, 0);
7933
7934 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
7935 zc_play_midi(tunes[index].data,loop);
7936
7937 if(tunes[index].start>0)
7938 zc_midi_seek(tunes[index].start);
7939
7940 midi_loop_start = tunes[index].loop_start;
7941 midi_loop_end = tunes[index].loop_end;
7942
7943 currmidi=index;
7944 master_volume(digi_volume, midi_volume);
7945 //midi_paused=false;
7946 64156 }
7947
7948 64156 void jukebox(int32_t index)
7949 {
7950
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index<0) index=MAXMIDIS-1;
7951
7952
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index>=MAXMIDIS) index=0;
7953
7954 // do nothing if it's already playing
7955
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64156 if(index==currmidi && midi_pos>=0)
7956 {
7957 return;
7958 }
7959
7960 64156 jukebox(index,tunes[index].loop);
7961 64156 }
7962
7963 100 void play_DmapMusic()
7964 {
7965
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if (is_headless())
7966 100 return;
7967
7968 static char tfile[2048];
7969 static int32_t ttrack=0;
7970 bool domidi=false;
7971
7972 int32_t fadeoutframes = 0;
7973 if (zcmusic != NULL)
7974 fadeoutframes = zcmusic->fadeoutframes;
7975
7976 if(DMaps[currdmap].tmusic[0]!=0)
7977 {
7978 if(zcmusic==NULL ||
7979 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
7980 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
7981 {
7982 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
7983 {
7984 if (play_enh_music_crossfade(DMaps[currdmap].tmusic, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
7985 {
7986 if (zcmusic != NULL)
7987 {
7988 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
7989 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
7990 }
7991 }
7992 }
7993 else
7994 {
7995 if (zcmusic != NULL)
7996 {
7997 zcmusic_stop(zcmusic);
7998 zcmusic_unload_file(zcmusic);
7999 zcmusic = NULL;
8000 zcmixer->newtrack = NULL;
8001 }
8002
8003 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
8004 zcmixer->newtrack = zcmusic;
8005
8006 if (zcmusic != NULL)
8007 {
8008 zc_stop_midi();
8009 strcpy(tfile, DMaps[currdmap].tmusic);
8010 zcmusic_play(zcmusic, emusic_volume);
8011 int32_t temptracks = 0;
8012 temptracks = zcmusic_get_tracks(zcmusic);
8013 temptracks = (temptracks < 2) ? 1 : temptracks;
8014 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8015 zcmusic_change_track(zcmusic, ttrack);
8016 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8017 }
8018 else
8019 {
8020 tfile[0] = 0;
8021 domidi = true;
8022 }
8023 }
8024 }
8025 }
8026 else
8027 {
8028 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8029 {
8030 play_enh_music_crossfade(NULL, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8031 }
8032 else
8033 {
8034 domidi = true;
8035 }
8036 }
8037
8038 if(domidi)
8039 {
8040 int32_t m=DMaps[currdmap].midi;
8041
8042 switch(m)
8043 {
8044 case 1:
8045 jukebox(ZC_MIDI_OVERWORLD);
8046 break;
8047
8048 case 2:
8049 jukebox(ZC_MIDI_DUNGEON);
8050 break;
8051
8052 case 3:
8053 jukebox(ZC_MIDI_LEVEL9);
8054 break;
8055
8056 default:
8057 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8058 jukebox(m+MIDIOFFSET_DMAP);
8059 else
8060 music_stop();
8061 }
8062 }
8063 100 }
8064
8065 34892 void playLevelMusic()
8066 {
8067
1/2
✓ Branch 0 taken 34892 times.
✗ Branch 1 not taken.
34892 if (is_headless())
8068 34892 return;
8069
8070 int32_t m=tmpscr->screen_midi;
8071
8072 switch(m)
8073 {
8074 case -2:
8075 music_stop();
8076 break;
8077
8078 case -1:
8079 play_DmapMusic();
8080 break;
8081
8082 case 1:
8083 jukebox(ZC_MIDI_OVERWORLD);
8084 break;
8085
8086 case 2:
8087 jukebox(ZC_MIDI_DUNGEON);
8088 break;
8089
8090 case 3:
8091 jukebox(ZC_MIDI_LEVEL9);
8092 break;
8093
8094 default:
8095 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8096 jukebox(m+MIDIOFFSET_MAPSCR);
8097 else
8098 music_stop();
8099 }
8100 34892 }
8101
8102 4275 void master_volume(int32_t dv,int32_t mv)
8103 {
8104
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2267 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 2267 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 300 times.
4275 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8105
8106
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2271 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 271 times.
✓ Branch 4 taken 2271 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 271 times.
4275 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8107
8108
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4275 times.
✓ Branch 2 taken 4275 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4275 times.
4275 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8109 4275 int32_t temp_vol = midi_volume;
8110
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 259 times.
4275 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8111 259 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8112 4275 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8113 4275 }
8114
8115 // array of voices, one for each sfx sample in the data file
8116 // 0+ = voice #
8117 // -1 = voice not allocated
8118 259 void Z_init_sound()
8119 {
8120
2/2
✓ Branch 0 taken 66304 times.
✓ Branch 1 taken 259 times.
66563 for(int32_t i=0; i<WAV_COUNT; i++)
8121 66304 sfx_voice[i]=-1;
8122
8123 259 const char* midis[ZC_MIDI_COUNT] = {
8124 "assets/dungeon.mid",
8125 "assets/ending.mid",
8126 "assets/gameover.mid",
8127 "assets/level9.mid",
8128 "assets/overworld.mid",
8129 "assets/title.mid",
8130 "assets/triforce.mid",
8131 };
8132
2/2
✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 259 times.
2072 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8133 {
8134 1813 tunes[i].data = load_midi(midis[i]);
8135
1/2
✓ Branch 0 taken 1813 times.
✗ Branch 1 not taken.
1813 if (!tunes[i].data)
8136 Z_error_fatal("Missing required file %s\n", midis[i]);
8137 1813 }
8138
8139
2/2
✓ Branch 0 taken 65268 times.
✓ Branch 1 taken 259 times.
65527 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8140 65268 tunes[ZC_MIDI_COUNT+j].data=NULL;
8141
8142 259 master_volume(digi_volume,midi_volume);
8143 259 }
8144
8145 // returns number of voices currently allocated
8146 int32_t sfx_count()
8147 {
8148 int32_t c=0;
8149
8150 for(int32_t i=0; i<WAV_COUNT; i++)
8151 if(sfx_voice[i]!=-1)
8152 ++c;
8153
8154 return c;
8155 }
8156
8157 // clean up finished samples
8158 18096941 void sfx_cleanup()
8159 {
8160
2/2
✓ Branch 0 taken 4632816896 times.
✓ Branch 1 taken 18096941 times.
4650913837 for(int32_t i=0; i<WAV_COUNT; i++)
8161
3/4
✓ Branch 0 taken 1256571 times.
✓ Branch 1 taken 4631560325 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256571 times.
4634073467 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8162 {
8163 1256571 deallocate_voice(sfx_voice[i]);
8164 1256571 sfx_voice[i]=-1;
8165 1256571 }
8166 18096941 }
8167
8168 1256708 SAMPLE* sfx_get_sample(int32_t index)
8169 {
8170 // check index
8171
2/4
✓ Branch 0 taken 1256708 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256708 times.
1256708 if (index<=0 || index>=WAV_COUNT)
8172 return nullptr;
8173
8174
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 810461 times.
1256708 if (sfxdat)
8175 {
8176
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8177 {
8178 446247 return (SAMPLE*)sfxdata[index].dat;
8179 }
8180 else
8181 {
8182 return (SAMPLE*)sfxdata[Z35].dat;
8183 }
8184 }
8185 else
8186 {
8187 810461 return &customsfxdata[index];
8188 }
8189
8190 return nullptr;
8191 1256708 }
8192
8193 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8194 // if a voice is already allocated (and/or playing), then it just returns true
8195 // Returns true: voice is allocated
8196 // false: unsuccessful
8197 1846603 bool sfx_init(int32_t index)
8198 {
8199 // check index
8200
3/4
✓ Branch 0 taken 1387384 times.
✓ Branch 1 taken 459219 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1387384 times.
1846603 if(index<=0 || index>=WAV_COUNT)
8201 459219 return false;
8202
8203
2/2
✓ Branch 0 taken 130722 times.
✓ Branch 1 taken 1256662 times.
1387384 if (sfx_voice[index] == -1)
8204 {
8205 1256662 SAMPLE* sample = sfx_get_sample(index);
8206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1256662 times.
1256662 if (!sample)
8207 return false;
8208
8209 1256662 sfx_voice[index] = allocate_voice(sample);
8210 1256662 }
8211
8212 1387384 return sfx_voice[index] != -1;
8213 1846603 }
8214
8215 int32_t sfx_get_default_freq(int32_t index)
8216 {
8217 if (sfxdat)
8218 {
8219 if (index < Z35)
8220 {
8221 return ((SAMPLE*)sfxdata[index].dat)->freq;
8222 }
8223 else
8224 {
8225 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8226 }
8227 }
8228 else
8229 {
8230 return customsfxdata[index].freq;
8231 }
8232 }
8233
8234 int32_t sfx_get_length(int32_t index)
8235 {
8236 if (sfxdat)
8237 {
8238 if (index < Z35)
8239 {
8240 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8241 }
8242 else
8243 {
8244 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8245 }
8246 }
8247 else
8248 {
8249 return int32_t(customsfxdata[index].len);
8250 }
8251 }
8252
8253 // plays an sfx sample
8254 1846603 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8255 {
8256
2/2
✓ Branch 0 taken 1387384 times.
✓ Branch 1 taken 459219 times.
1846603 if(!sfx_init(index))
8257 459219 return;
8258
1/2
✓ Branch 0 taken 1387384 times.
✗ Branch 1 not taken.
1387384 if (!is_headless())
8259 {
8260 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8261 voice_set_pan(sfx_voice[index], pan);
8262
8263 // Only used by ZScript currently
8264 if (freq <= -1)
8265 {
8266 freq = sfx_get_default_freq(index);
8267 }
8268 voice_set_frequency(sfx_voice[index], freq);
8269
8270 // Only used by ZScript currently
8271 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8272 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8273 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8274 voice_set_volume(sfx_voice[index], temp_volume);
8275
8276 int32_t pos = voice_get_position(sfx_voice[index]);
8277
8278 if (restart) voice_set_position(sfx_voice[index], 0);
8279
8280 if (pos <= 0)
8281 voice_start(sfx_voice[index]);
8282 }
8283
8284
4/4
✓ Branch 0 taken 856165 times.
✓ Branch 1 taken 531219 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 856157 times.
1387384 if (restart && replay_is_debug())
8285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 856157 times.
856157 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8286 1846603 }
8287
8288 // true if sfx is allocated
8289 198397 bool sfx_allocated(int32_t index)
8290 {
8291
3/4
✓ Branch 0 taken 33450 times.
✓ Branch 1 taken 164947 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33450 times.
198397 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8292 }
8293
8294 // start it (in loop mode) if it's not already playing,
8295 // otherwise adjust it to play in loop mode -DD
8296 116943 void cont_sfx(int32_t index)
8297 {
8298
1/2
✓ Branch 0 taken 116943 times.
✗ Branch 1 not taken.
116943 if (is_headless())
8299 116943 return;
8300
8301 if(!sfx_init(index))
8302 {
8303 return;
8304 }
8305
8306 if(voice_get_position(sfx_voice[index])<=0)
8307 {
8308 voice_set_position(sfx_voice[index],0);
8309 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8310 voice_set_volume(sfx_voice[index], sfx_volume);
8311 voice_start(sfx_voice[index]);
8312 }
8313 else
8314 {
8315 adjust_sfx(index, 128, true);
8316 }
8317 116943 }
8318
8319 // adjust parameters while playing
8320 4903 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8321 {
8322
4/6
✓ Branch 0 taken 4467 times.
✓ Branch 1 taken 436 times.
✓ Branch 2 taken 4467 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4467 times.
4903 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8323 4903 return;
8324
8325 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8326 voice_set_pan(sfx_voice[index],pan);
8327 4903 }
8328
8329 // pauses a voice
8330 3223 void pause_sfx(int32_t index)
8331 {
8332
3/6
✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3223 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3223 times.
3223 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8333 voice_stop(sfx_voice[index]);
8334 3223 }
8335
8336 // resumes a voice
8337 1360 void resume_sfx(int32_t index)
8338 {
8339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1360 times.
1360 if (is_headless())
8340 1360 return;
8341
8342 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8343 voice_start(sfx_voice[index]);
8344 1360 }
8345
8346 // pauses all active voices
8347 1072 void pause_all_sfx()
8348 {
8349
2/2
✓ Branch 0 taken 274432 times.
✓ Branch 1 taken 1072 times.
275504 for(int32_t i=0; i<WAV_COUNT; i++)
8350
2/2
✓ Branch 0 taken 274430 times.
✓ Branch 1 taken 2 times.
274434 if(sfx_voice[i]!=-1)
8351 2 voice_stop(sfx_voice[i]);
8352 1072 }
8353
8354 // resumes all paused voices
8355 1017 void resume_all_sfx()
8356 {
8357
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8358
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8359 voice_start(sfx_voice[i]);
8360 1017 }
8361
8362 // stops an sfx and deallocates the voice
8363 14459030 void stop_sfx(int32_t index)
8364 {
8365
3/4
✓ Branch 0 taken 14212707 times.
✓ Branch 1 taken 246323 times.
✓ Branch 2 taken 14212707 times.
✗ Branch 3 not taken.
14459030 if(index<=0 || index>=WAV_COUNT)
8366 246323 return;
8367
8368
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 14212674 times.
14212707 if(sfx_voice[index]!=-1)
8369 {
8370 33 deallocate_voice(sfx_voice[index]);
8371 33 sfx_voice[index]=-1;
8372 33 }
8373 14459030 }
8374
8375 // Stops SFX played by Hero's item of the given family
8376 129758 void stop_item_sfx(int32_t family)
8377 {
8378 129758 int32_t id=current_item_id(family);
8379
8380
2/2
✓ Branch 0 taken 128658 times.
✓ Branch 1 taken 1100 times.
129758 if(id<0)
8381 128658 return;
8382
8383 1100 stop_sfx(itemsbuf[id].usesound);
8384 129758 }
8385
8386 9182 void kill_sfx()
8387 {
8388
2/2
✓ Branch 0 taken 2350592 times.
✓ Branch 1 taken 9182 times.
2359774 for(int32_t i=0; i<WAV_COUNT; i++)
8389
2/2
✓ Branch 0 taken 2350534 times.
✓ Branch 1 taken 58 times.
2350650 if(sfx_voice[i]!=-1)
8390 {
8391 58 deallocate_voice(sfx_voice[i]);
8392 58 sfx_voice[i]=-1;
8393 58 }
8394 9182 }
8395
8396 1172448 int32_t pan(int32_t x)
8397 {
8398
1/4
✓ Branch 0 taken 1172448 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1172448 switch(pan_style)
8399 {
8400 case 0:
8401 return 128;
8402
8403 case 1:
8404 1172448 return vbound((x>>1)+68,0,255);
8405
8406 case 2:
8407 return vbound(((x*3)>>2)+36,0,255);
8408 }
8409
8410 return vbound(x,0,255);
8411 1172448 }
8412
8413 49811030 bool joybtn(int32_t b)
8414 {
8415
1/2
✓ Branch 0 taken 49811030 times.
✗ Branch 1 not taken.
49811030 if(b == 0)
8416 return false;
8417
1/2
✓ Branch 0 taken 49811030 times.
✗ Branch 1 not taken.
49811030 if (b-1 >= joy[joystick_index].num_buttons)
8418 49811030 return false;
8419
8420 return joy[joystick_index].button[b-1].b !=0;
8421 49811030 }
8422
8423 bool joystick(int32_t s)
8424 {
8425 if(s < 0)
8426 return false;
8427 if (s >= joy[joystick_index].num_sticks)
8428 return false;
8429
8430 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8431 {
8432 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8433 return true;
8434 }
8435 return false;
8436 }
8437
8438 const char* joybtn_name(int32_t b)
8439 {
8440 if (b <= 0 || b > joy[joystick_index].num_buttons)
8441 return "";
8442
8443 return joy[joystick_index].button[b-1].name;
8444 }
8445
8446 const char* joystick_name(int32_t s)
8447 {
8448 if (s < 0 || s >= joy[joystick_index].num_sticks)
8449 return "";
8450
8451 return joy[joystick_index].stick[s].name;
8452 }
8453
8454 int32_t button_pressed()
8455 {
8456 if (joystick_index >= MAX_JOYSTICKS)
8457 return 0;
8458
8459 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8460 {
8461 if(joybtn(i))
8462 return i;
8463 }
8464
8465 return 0;
8466 }
8467
8468 int32_t next_press_key();
8469
8470 int32_t next_joy_input(bool buttons)
8471 {
8472 clear_keybuf();
8473
8474 //first, we need to wait until they're pressing no buttons
8475 for(;;)
8476 {
8477 if(keypressed())
8478 {
8479 switch(readkey()>>8)
8480 {
8481 case KEY_ESC:
8482 return -1;
8483
8484 case KEY_SPACE:
8485 return 0;
8486 }
8487 }
8488
8489 poll_joystick();
8490 bool done = true;
8491
8492 if (buttons)
8493 {
8494 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8495 {
8496 if(joybtn(i)) done = false;
8497 }
8498 }
8499 else
8500 {
8501 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8502 {
8503 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8504 return -2;
8505 }
8506 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8507 {
8508 if(joystick(i)) done = false;
8509 }
8510 }
8511
8512 if(done) break;
8513 rest(1);
8514 }
8515
8516 //now, we need to wait for them to press any button
8517 for(;;)
8518 {
8519 if(keypressed())
8520 {
8521 switch(readkey()>>8)
8522 {
8523 case KEY_ESC:
8524 return -1;
8525
8526 case KEY_SPACE:
8527 return 0;
8528 }
8529 }
8530
8531 poll_joystick();
8532
8533 if (buttons)
8534 {
8535 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8536 {
8537 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8538 return -2;
8539 }
8540 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8541 {
8542 if(joybtn(i))
8543 return i;
8544 }
8545 }
8546 else
8547 {
8548 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8549 {
8550 if(joystick(i))
8551 return i;
8552 }
8553 }
8554 rest(1);
8555 }
8556 }
8557
8558 7223275 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8559 {
8560
2/2
✓ Branch 0 taken 7197737 times.
✓ Branch 1 taken 25538 times.
7223275 bool ret = btn && !flag;
8561 7223275 flag = rawbtn;
8562
8563 7223275 return ret;
8564 }
8565 373345476 static bool rButton(bool &btn, bool &flag)
8566 {
8567
2/2
✓ Branch 0 taken 359587435 times.
✓ Branch 1 taken 13758041 times.
373345476 bool ret = btn && !flag;
8568 373345476 flag = btn;
8569
8570 373345476 return ret;
8571 }
8572 4574878 static bool rButtonPeek(bool btn, bool flag)
8573 {
8574
2/2
✓ Branch 0 taken 4234696 times.
✓ Branch 1 taken 340182 times.
4574878 if(!btn)
8575 {
8576 4234696 return false;
8577 }
8578
2/2
✓ Branch 0 taken 33303 times.
✓ Branch 1 taken 306879 times.
340182 else if(!flag)
8579 {
8580 33303 return true;
8581 }
8582
8583 306879 return false;
8584 4574878 }
8585
8586 // Updated only by keyboard/gamepad.
8587 // If in replay mode, this is set directly by the replay system.
8588 // This should never be read from directly - use control_state instead.
8589 bool raw_control_state[ZC_CONTROL_STATES];
8590
8591 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8592 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8593 // lasts until the next call to load_control_state.
8594 bool control_state[ZC_CONTROL_STATES];
8595 bool disable_control[ZC_CONTROL_STATES];
8596 bool drunk_toggle_state[11];
8597 bool disabledKeys[127];
8598 bool KeyInput[127];
8599 bool KeyPress[127];
8600
8601 bool key_current_frame[127];
8602 bool key_previous_frame[127];
8603
8604 static bool key_system[127];
8605 static bool key_system_previous[127];
8606 static bool key_system_press[127];
8607
8608 bool button_press[ZC_CONTROL_STATES];
8609 bool button_hold[ZC_CONTROL_STATES];
8610
8611 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8612 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8613 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8614 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8615 #define STICK_PRECISION 56 //define your own sensitivity
8616
8617 15491880 void load_control_state()
8618 {
8619 15491880 load_control_called_this_frame = true;
8620
8621
2/2
✓ Branch 0 taken 12362248 times.
✓ Branch 1 taken 3129632 times.
15491880 if (replay_version_check(8, 11))
8622 {
8623
2/2
✓ Branch 0 taken 56333376 times.
✓ Branch 1 taken 3129632 times.
59463008 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8624 56333376 down_control_states[i] = raw_control_state[i];
8625 3129632 }
8626
8627
2/2
✓ Branch 0 taken 15491859 times.
✓ Branch 1 taken 21 times.
15491880 if (!replay_is_replaying())
8628 {
8629
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8630
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8631
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8632
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8643
8644
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8645 {
8646 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8647 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8648 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8649 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8650 }
8651 else
8652 {
8653 21 raw_control_state[14] = false;
8654 21 raw_control_state[15] = false;
8655 21 raw_control_state[16] = false;
8656 21 raw_control_state[17] = false;
8657 }
8658 21 }
8659
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15491875 times.
15491880 if (replay_is_active())
8660 {
8661
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14280175 times.
15491875 if (replay_get_version() < 3)
8662 1211700 replay_poll();
8663
4/4
✓ Branch 0 taken 14280154 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12518779 times.
✓ Branch 3 taken 1761375 times.
14280175 else if (replay_is_replaying() && replay_get_version() < 6)
8664 1761375 replay_peek_input();
8665
4/4
✓ Branch 0 taken 12518779 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9389147 times.
✓ Branch 3 taken 3129632 times.
12518800 else if (replay_is_replaying() && replay_version_check(8, 11))
8666 3129632 replay_peek_input();
8667
2/2
✓ Branch 0 taken 14225363 times.
✓ Branch 1 taken 1266512 times.
15491875 if (replay_get_version() == 8)
8668 1266512 update_keys();
8669 15491875 }
8670
8671 // Some test replay files were made before a serious input bug was fixed, so instead
8672 // of re-doing them or tossing them out, just check for that zplay version.
8673
3/4
✓ Branch 0 taken 15491870 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15369970 times.
15491880 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8674
2/2
✓ Branch 0 taken 278853660 times.
✓ Branch 1 taken 15491870 times.
294345530 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8675 {
8676 278853660 control_state[i] = raw_control_state[i];
8677
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 225829638 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
278853660 if (botched_input && !control_state[i])
8678 50412028 down_control_states[i] = false;
8679 278853660 }
8680 15491870 bool did_bad_cutscene_btn = false;
8681
2/2
✓ Branch 0 taken 15491870 times.
✓ Branch 1 taken 278853660 times.
294345530 for(int q = 0; q < 18; ++q)
8682
4/4
✓ Branch 0 taken 13189321 times.
✓ Branch 1 taken 265664339 times.
✓ Branch 2 taken 13187738 times.
✓ Branch 3 taken 1583 times.
278855243 if(control_state[q] && !active_cutscene.can_button(q))
8683 {
8684 1583 control_state[q] = false;
8685 1583 did_bad_cutscene_btn = true;
8686 1583 }
8687
2/2
✓ Branch 0 taken 15490725 times.
✓ Branch 1 taken 1145 times.
15491870 if(did_bad_cutscene_btn)
8688 1145 active_cutscene.error();
8689
8690 15491870 button_press[0]=rButton(control_state[0],button_hold[0]);
8691 15491870 button_press[1]=rButton(control_state[1],button_hold[1]);
8692 15491870 button_press[2]=rButton(control_state[2],button_hold[2]);
8693 15491870 button_press[3]=rButton(control_state[3],button_hold[3]);
8694 15491870 button_press[4]=rButton(control_state[4],button_hold[4]);
8695 15491870 button_press[5]=rButton(control_state[5],button_hold[5]);
8696 15491870 button_press[6]=rButton(control_state[6],button_hold[6]);
8697 15491870 button_press[7]=rButton(control_state[7],button_hold[7]);
8698 15491870 button_press[8]=rButton(control_state[8],button_hold[8]);
8699 15491870 button_press[9]=rButton(control_state[9],button_hold[9]);
8700 15491870 button_press[10]=rButton(control_state[10],button_hold[10]);
8701 15491870 button_press[11]=rButton(control_state[11],button_hold[11]);
8702 15491870 button_press[12]=rButton(control_state[12],button_hold[12]);
8703 15491870 button_press[13]=rButton(control_state[13],button_hold[13]);
8704 15491870 button_press[14]=rButton(control_state[14],button_hold[14]);
8705 15491870 button_press[15]=rButton(control_state[15],button_hold[15]);
8706 15491870 button_press[16]=rButton(control_state[16],button_hold[16]);
8707 15491870 button_press[17]=rButton(control_state[17],button_hold[17]);
8708 15491870 }
8709
8710 // Returns true if any game key is pressed. This is needed because keypressed()
8711 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8712 77753533 bool zc_key_pressed()
8713 //may also need to use zc_getrawkey
8714 {
8715
7/10
✓ Branch 0 taken 62789338 times.
✓ Branch 1 taken 14964195 times.
✓ Branch 2 taken 14964195 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14964195 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12251700 times.
✓ Branch 7 taken 12251700 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4902281 times.
82655814 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8716
4/6
✓ Branch 0 taken 12251700 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12251700 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9327449 times.
✓ Branch 5 taken 9327449 times.
12251700 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8717
4/6
✓ Branch 0 taken 9327449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9327449 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6180364 times.
✓ Branch 5 taken 6180364 times.
9327449 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8718
4/6
✓ Branch 0 taken 6180364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6180364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5305833 times.
✓ Branch 5 taken 5305833 times.
6180364 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8719
1/2
✓ Branch 0 taken 5305833 times.
✗ Branch 1 not taken.
5305833 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8720
3/4
✓ Branch 0 taken 5120166 times.
✓ Branch 1 taken 185667 times.
✓ Branch 2 taken 5120166 times.
✗ Branch 3 not taken.
5305833 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8721
3/4
✓ Branch 0 taken 4974061 times.
✓ Branch 1 taken 146105 times.
✓ Branch 2 taken 4974061 times.
✗ Branch 3 not taken.
5120166 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8722
3/4
✓ Branch 0 taken 4953191 times.
✓ Branch 1 taken 20870 times.
✓ Branch 2 taken 4953191 times.
✗ Branch 3 not taken.
4974061 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8723
3/4
✓ Branch 0 taken 4926832 times.
✓ Branch 1 taken 26359 times.
✓ Branch 2 taken 4926832 times.
✗ Branch 3 not taken.
4953191 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8724
3/4
✓ Branch 0 taken 4919547 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4919547 times.
✗ Branch 3 not taken.
4926832 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8725
3/4
✓ Branch 0 taken 4904194 times.
✓ Branch 1 taken 15353 times.
✓ Branch 2 taken 4904194 times.
✗ Branch 3 not taken.
4919547 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8726
3/4
✓ Branch 0 taken 4902375 times.
✓ Branch 1 taken 1819 times.
✓ Branch 2 taken 4902375 times.
✗ Branch 3 not taken.
4904194 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8727
3/4
✓ Branch 0 taken 4902340 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4902340 times.
✗ Branch 3 not taken.
4902375 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8728
2/2
✓ Branch 0 taken 4902281 times.
✓ Branch 1 taken 59 times.
4902340 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8729 138981944 return true;
8730
8731 4902281 return false;
8732 18305549 }
8733
8734 294512756 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8735 {
8736 294512756 bool ret = false, drunkstate = false, rawret = false;;
8737 294512756 bool* flag = &down_control_states[btn];
8738
2/7
✓ Branch 0 taken 276188411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18324345 times.
294512756 switch(btn)
8739 {
8740 case btnF12:
8741 ret = zc_getkey(KEY_F12, ignoreDisable);
8742 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8743 eatEntirely = false;
8744 break;
8745 case btnF11:
8746 ret = zc_getkey(KEY_F11, ignoreDisable);
8747 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8748 eatEntirely = false;
8749 break;
8750 case btnF5:
8751 ret = zc_getkey(KEY_F5, ignoreDisable);
8752 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8753 eatEntirely = false;
8754 break;
8755 case btnQ:
8756 ret = zc_getkey(KEY_Q, ignoreDisable);
8757 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8758 eatEntirely = false;
8759 break;
8760 case btnI:
8761 ret = zc_getkey(KEY_I, ignoreDisable);
8762 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8763 eatEntirely = false;
8764 break;
8765 case btnM:
8766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18324345 times.
18324345 if(FFCore.kb_typing_mode) return false;
8767 18324345 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8768 18324345 eatEntirely = false;
8769 18324345 break;
8770 default: //control_state[] index
8771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276188411 times.
276188411 if(FFCore.kb_typing_mode) return false;
8772
6/6
✓ Branch 0 taken 274810473 times.
✓ Branch 1 taken 1377938 times.
✓ Branch 2 taken 16497121 times.
✓ Branch 3 taken 258313352 times.
✓ Branch 4 taken 16496968 times.
✓ Branch 5 taken 153 times.
276188411 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8773
2/2
✓ Branch 0 taken 15722347 times.
✓ Branch 1 taken 260465911 times.
276188258 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8774
4/4
✓ Branch 0 taken 245422514 times.
✓ Branch 1 taken 30765897 times.
✓ Branch 2 taken 7154 times.
✓ Branch 3 taken 30758743 times.
306954308 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8775 276188411 rawret = raw_control_state[btn];
8776 276188411 }
8777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294512756 times.
294512756 assert(flag);
8778
2/2
✓ Branch 0 taken 188222787 times.
✓ Branch 1 taken 106289969 times.
294512756 if(press)
8779 {
8780
2/2
✓ Branch 0 taken 4574878 times.
✓ Branch 1 taken 101715091 times.
106289969 if(peek)
8781 4574878 ret = rButtonPeek(ret, *flag);
8782
2/2
✓ Branch 0 taken 94491816 times.
✓ Branch 1 taken 7223275 times.
101715091 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8783 7223275 else ret = rButton(ret, *flag, rawret);
8784 106289969 }
8785
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 294512756 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
294512756 if(eatEntirely && ret) control_state[btn] = false;
8786
4/4
✓ Branch 0 taken 220049377 times.
✓ Branch 1 taken 74463379 times.
✓ Branch 2 taken 220049296 times.
✓ Branch 3 taken 81 times.
294512756 if(drunk && drunkstate) ret = !ret;
8787 294512756 return ret;
8788 294512756 }
8789
8790 14790555 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8791 {
8792 14790555 byte ret = 0;
8793
2/2
✓ Branch 0 taken 10439109 times.
✓ Branch 1 taken 4351446 times.
14790555 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8794
2/2
✓ Branch 0 taken 14583326 times.
✓ Branch 1 taken 207229 times.
14790555 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8795
2/2
✓ Branch 0 taken 14583773 times.
✓ Branch 1 taken 206782 times.
14790555 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8796
2/2
✓ Branch 0 taken 14583773 times.
✓ Branch 1 taken 206782 times.
14790555 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8797
2/2
✓ Branch 0 taken 14583773 times.
✓ Branch 1 taken 206782 times.
14790555 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8798
2/2
✓ Branch 0 taken 14583773 times.
✓ Branch 1 taken 206782 times.
14790555 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8799
2/2
✓ Branch 0 taken 14583773 times.
✓ Branch 1 taken 206782 times.
14790555 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8800
2/2
✓ Branch 0 taken 14583658 times.
✓ Branch 1 taken 206897 times.
14790555 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8801 14790555 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8802 }
8803
8804 7010 byte checkIntBtnVal(byte intbtn, byte vals)
8805 {
8806 7010 return intbtn&vals;
8807 }
8808
8809 3708454 bool Up()
8810 {
8811 3708454 return getInput(btnUp);
8812 }
8813 726512 bool Down()
8814 {
8815 726512 return getInput(btnDown);
8816 }
8817 979535 bool Left()
8818 {
8819 979535 return getInput(btnLeft);
8820 }
8821 1040252 bool Right()
8822 {
8823 1040252 return getInput(btnRight);
8824 }
8825 532139 bool cAbtn()
8826 {
8827 532139 return getInput(btnA);
8828 }
8829 3306978 bool cBbtn()
8830 {
8831 3306978 return getInput(btnB);
8832 }
8833 bool cSbtn()
8834 {
8835 return getInput(btnS);
8836 }
8837 208608 bool cLbtn()
8838 {
8839 208608 return getInput(btnL);
8840 }
8841 208608 bool cRbtn()
8842 {
8843 208608 return getInput(btnR);
8844 }
8845 bool cPbtn()
8846 {
8847 return getInput(btnP);
8848 }
8849 bool cEx1btn()
8850 {
8851 return getInput(btnEx1);
8852 }
8853 bool cEx2btn()
8854 {
8855 return getInput(btnEx2);
8856 }
8857 bool cEx3btn()
8858 {
8859 return getInput(btnEx3);
8860 }
8861 bool cEx4btn()
8862 {
8863 return getInput(btnEx4);
8864 }
8865 bool AxisUp()
8866 {
8867 return getInput(btnAxisUp);
8868 }
8869 bool AxisDown()
8870 {
8871 return getInput(btnAxisDown);
8872 }
8873 bool AxisLeft()
8874 {
8875 return getInput(btnAxisLeft);
8876 }
8877 bool AxisRight()
8878 {
8879 return getInput(btnAxisRight);
8880 }
8881
8882 bool cMbtn()
8883 {
8884 return getInput(btnM);
8885 }
8886 bool cF12()
8887 {
8888 return getInput(btnF12);
8889 }
8890 bool cF11()
8891 {
8892 return getInput(btnF11);
8893 }
8894 bool cF5()
8895 {
8896 return getInput(btnF5);
8897 }
8898 bool cQ()
8899 {
8900 return getInput(btnQ);
8901 }
8902 bool cI()
8903 {
8904 return getInput(btnI);
8905 }
8906
8907 208304 bool rUp()
8908 {
8909 208304 return getInput(btnUp, true);
8910 }
8911 208096 bool rDown()
8912 {
8913 208096 return getInput(btnDown, true);
8914 }
8915 207900 bool rLeft()
8916 {
8917 207900 return getInput(btnLeft, true);
8918 }
8919 207171 bool rRight()
8920 {
8921 207171 return getInput(btnRight, true);
8922 }
8923 6570 bool rAbtn()
8924 {
8925 6570 return getInput(btnA, true);
8926 }
8927 4619 bool rBbtn()
8928 {
8929 4619 return getInput(btnB, true);
8930 }
8931 14361232 bool rSbtn()
8932 {
8933 14361232 return getInput(btnS, true);
8934 }
8935 18305549 bool rMbtn()
8936 {
8937 18305549 return getInput(btnM, true);
8938 }
8939 185250 bool rLbtn()
8940 {
8941 185250 return getInput(btnL, true);
8942 }
8943 185245 bool rRbtn()
8944 {
8945 185245 return getInput(btnR, true);
8946 }
8947 14361965 bool rPbtn()
8948 {
8949 14361965 return getInput(btnP, true);
8950 }
8951 bool rEx1btn()
8952 {
8953 return getInput(btnEx1, true);
8954 }
8955 bool rEx2btn()
8956 {
8957 return getInput(btnEx2, true);
8958 }
8959 195896 bool rEx3btn()
8960 {
8961 195896 return getInput(btnEx3, true);
8962 }
8963 195896 bool rEx4btn()
8964 {
8965 195896 return getInput(btnEx4, true);
8966 }
8967 bool rAxisUp()
8968 {
8969 return getInput(btnAxisUp, true);
8970 }
8971 bool rAxisDown()
8972 {
8973 return getInput(btnAxisDown, true);
8974 }
8975 bool rAxisLeft()
8976 {
8977 return getInput(btnAxisLeft, true);
8978 }
8979 bool rAxisRight()
8980 {
8981 return getInput(btnAxisRight, true);
8982 }
8983
8984 bool rF11()
8985 {
8986 return getInput(btnF11, true);
8987 }
8988 bool rQ()
8989 {
8990 return getInput(btnQ, true);
8991 }
8992 bool rI()
8993 {
8994 return getInput(btnI, true);
8995 }
8996
8997 36568792 bool DrunkUp()
8998 {
8999 36568792 return getInput(btnUp, false, true);
9000 }
9001 33371581 bool DrunkDown()
9002 {
9003 33371581 return getInput(btnDown, false, true);
9004 }
9005 19572701 bool DrunkLeft()
9006 {
9007 19572701 return getInput(btnLeft, false, true);
9008 }
9009 16653543 bool DrunkRight()
9010 {
9011 16653543 return getInput(btnRight, false, true);
9012 }
9013 15766158 bool DrunkcAbtn()
9014 {
9015 15766158 return getInput(btnA, false, true);
9016 }
9017 15202844 bool DrunkcBbtn()
9018 {
9019 15202844 return getInput(btnB, false, true);
9020 }
9021 14153172 bool DrunkcEx1btn()
9022 {
9023 14153172 return getInput(btnEx1, false, true);
9024 }
9025 14151804 bool DrunkcEx2btn()
9026 {
9027 14151804 return getInput(btnEx2, false, true);
9028 }
9029 bool DrunkcSbtn()
9030 {
9031 return getInput(btnS, false, true);
9032 }
9033 bool DrunkcMbtn()
9034 {
9035 return getInput(btnM, false, true);
9036 }
9037 bool DrunkcLbtn()
9038 {
9039 return getInput(btnL, false, true);
9040 }
9041 bool DrunkcRbtn()
9042 {
9043 return getInput(btnR, false, true);
9044 }
9045 bool DrunkcPbtn()
9046 {
9047 return getInput(btnP, false, true);
9048 }
9049
9050 bool DrunkrUp()
9051 {
9052 return getInput(btnUp, true, true);
9053 }
9054 bool DrunkrDown()
9055 {
9056 return getInput(btnDown, true, true);
9057 }
9058 bool DrunkrLeft()
9059 {
9060 return getInput(btnLeft, true, true);
9061 }
9062 bool DrunkrRight()
9063 {
9064 return getInput(btnRight, true, true);
9065 }
9066 11825550 bool DrunkrAbtn()
9067 {
9068 11825550 return getInput(btnA, true, true);
9069 }
9070 11854082 bool DrunkrBbtn()
9071 {
9072 11854082 return getInput(btnB, true, true);
9073 }
9074 502081 bool DrunkrEx1btn()
9075 {
9076 502081 return getInput(btnEx1, true, true);
9077 }
9078 501902 bool DrunkrEx2btn()
9079 {
9080 501902 return getInput(btnEx2, true, true);
9081 }
9082 bool DrunkrEx3btn()
9083 {
9084 return getInput(btnEx3, true, true);
9085 }
9086 bool DrunkrEx4btn()
9087 {
9088 return getInput(btnEx4, true, true);
9089 }
9090 bool DrunkrSbtn()
9091 {
9092 return getInput(btnS, true, true);
9093 }
9094 bool DrunkrMbtn()
9095 {
9096 return getInput(btnM, true, true);
9097 }
9098 12890875 bool DrunkrLbtn()
9099 {
9100 12890875 return getInput(btnL, true, true);
9101 }
9102 12885570 bool DrunkrRbtn()
9103 {
9104 12885570 return getInput(btnR, true, true);
9105 }
9106 bool DrunkrPbtn()
9107 {
9108 return getInput(btnP, true, true);
9109 }
9110
9111 18796 void eat_buttons()
9112 {
9113 18796 getInput(btnA, true, false, true);
9114 18796 getInput(btnB, true, false, true);
9115 18796 getInput(btnS, true, false, true);
9116 18796 getInput(btnM, true, false, true);
9117 18796 getInput(btnL, true, false, true);
9118 18796 getInput(btnR, true, false, true);
9119 18796 getInput(btnP, true, false, true);
9120 18796 getInput(btnEx1, true, false, true);
9121 18796 getInput(btnEx2, true, false, true);
9122 18796 getInput(btnEx3, true, false, true);
9123 18796 getInput(btnEx4, true, false, true);
9124 18796 }
9125
9126 // Is true for the _first frame_ of a key press.
9127 // But! it is possible that a script manually sets the value of KeyPress,
9128 // in which case it will be restored to the "true" value based on `key_current_frame`
9129 // and `key_previous_frame` on the next frame.
9130 55 bool zc_readkey(int32_t k, bool ignoreDisable)
9131 {
9132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(ignoreDisable) return KeyPress[k];
9133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 switch(k)
9134 {
9135 case KEY_F7:
9136 case KEY_F8:
9137 case KEY_F9:
9138 return KeyPress[k];
9139
9140 default:
9141
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 10 times.
55 return KeyPress[k] && !disabledKeys[k];
9142 }
9143 55 }
9144
9145 // Is true for _every frame_ a key is held down.
9146 // But! it is possible that a script manually sets the value of KeyInput,
9147 // in which case it will be restored to the "true" value based on `key_current_frame`
9148 // on the next frame.
9149 bool zc_getkey(int32_t k, bool ignoreDisable)
9150 {
9151 if(ignoreDisable) return KeyInput[k];
9152 switch(k)
9153 {
9154 case KEY_F7:
9155 case KEY_F8:
9156 case KEY_F9:
9157 return KeyInput[k];
9158
9159 default:
9160 return KeyInput[k] && !disabledKeys[k];
9161 }
9162 }
9163
9164 // Reads (and then clears) the current frame key state directly.
9165 // Scripts can also modify `key_current_frame`.
9166 916 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9167 {
9168
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 914 times.
916 if(zc_getrawkey(k, ignoreDisable))
9169 {
9170 2 _key[k]=key[k]=key_current_frame[k]=0;
9171 2 return true;
9172 }
9173 914 _key[k]=key[k]=key_current_frame[k]=0;
9174 914 return false;
9175 916 }
9176
9177 // Reads the current frame key state directly.
9178 // Scripts can also modify `key_current_frame`.
9179 124263351 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9180 {
9181
2/2
✓ Branch 0 taken 105957692 times.
✓ Branch 1 taken 18305659 times.
124263351 if(ignoreDisable) return key_current_frame[k];
9182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305659 times.
18305659 switch(k)
9183 {
9184 case KEY_F7:
9185 case KEY_F8:
9186 case KEY_F9:
9187 return key_current_frame[k];
9188
9189 default:
9190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18305659 times.
18305659 return key_current_frame[k] && !disabledKeys[k];
9191 }
9192 124263351 }
9193
9194 // Only used for a handful of keys, like tilde and Function keys.
9195 // This state is never read within the game.
9196 // It exists so that all keyboard input still functions during replay,
9197 // without inadvertently doing things like toggling throttling if the player
9198 // presses ~
9199 bool zc_get_system_key(int32_t k)
9200 {
9201 return key_system[k];
9202 }
9203
9204 // True for the _first_ frame of a key press.
9205 164749941 bool zc_read_system_key(int32_t k)
9206 {
9207 164749941 return key_system_press[k];
9208 }
9209
9210 2324804723 bool is_system_key(int32_t k)
9211 {
9212
2/2
✓ Branch 0 taken 2160054782 times.
✓ Branch 1 taken 164749941 times.
2324804723 switch (k)
9213 {
9214 case KEY_BACKQUOTE:
9215 case KEY_CLOSEBRACE:
9216 case KEY_END:
9217 case KEY_HOME:
9218 case KEY_OPENBRACE:
9219 case KEY_PGDN:
9220 case KEY_PGUP:
9221 case KEY_TAB:
9222 case KEY_TILDE:
9223 164749941 return true;
9224 }
9225 2160054782 return is_Fkey(k);
9226 2324804723 }
9227
9228 18305549 void update_system_keys()
9229 {
9230
2/2
✓ Branch 0 taken 2324804723 times.
✓ Branch 1 taken 18305549 times.
2343110272 for (int32_t q = 0; q < 127; ++q)
9231 {
9232
2/2
✓ Branch 0 taken 384416529 times.
✓ Branch 1 taken 1940388194 times.
2324804723 if (!is_system_key(q))
9233 1940388194 continue;
9234
9235 384416529 key_system[q] = key[q];
9236
1/2
✓ Branch 0 taken 384416529 times.
✗ Branch 1 not taken.
384416529 key_system_press[q] = key_system[q] && !key_system_previous[q];
9237 384416529 key_system_previous[q] = key_system[q];
9238 384416529 }
9239 18305549 }
9240
9241 19572061 void update_keys()
9242 {
9243
2/2
✓ Branch 0 taken 2485651747 times.
✓ Branch 1 taken 19572061 times.
2505223808 for (int32_t q = 0; q < 127; ++q)
9244 {
9245 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9246
2/2
✓ Branch 0 taken 2485639047 times.
✓ Branch 1 taken 12700 times.
2485651747 if (!replay_is_replaying())
9247 12700 key_current_frame[q] = key[q];
9248
9249
2/2
✓ Branch 0 taken 2466562549 times.
✓ Branch 1 taken 19089198 times.
2485651747 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9250 2485651747 KeyInput[q] = key_current_frame[q];
9251 2485651747 key_previous_frame[q] = key_current_frame[q];
9252 2485651747 }
9253 19572061 }
9254
9255 bool zc_disablekey(int32_t k, bool val)
9256 {
9257 switch(k)
9258 {
9259 case KEY_F7:
9260 case KEY_F8:
9261 case KEY_F9:
9262 return false;
9263
9264 default:
9265 disabledKeys[k] = val;
9266 return true;
9267 }
9268 }
9269
9270 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9271 {
9272 timer=timer;
9273 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9274 }
9275